This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Add MyBatis support #404
Copy link
Copy link
Closed as not planned
Labels
for: external-projectFor an external project and not something we can fixjvm-reachability-metadataShould be supported via the GraalVM JVM Reachability Metadata Repository once availabletype: compatibilityNative image compatibility issue
Description
I used Springboot+MybatisPlus in the project When I did not add MybatisPlus, I could successfully build a native image and run it successfully.
Join MybatisPlus, although it can be compiled and generated native image, but the running error. Error memory is as follows:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-12 08:23:32.757 ERROR 4751 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.fandow.oa.OaStaffApplication#MapperScannerRegistrar#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.mybatis.spring.mapper.MapperScannerConfigurer]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.mybatis.spring.mapper.MapperScannerConfigurer.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1318) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1216) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[na:na]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:122) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:751) ~[na:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:569) ~[na:na]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[na:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[na:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[na:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[na:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[na:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[na:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[na:na]
at com.fandow.oa.OaStaffApplication.main(OaStaffApplication.java:22) ~[com.fandow.oa.oastaffapplication:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.mybatis.spring.mapper.MapperScannerConfigurer]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.mybatis.spring.mapper.MapperScannerConfigurer.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1310) ~[na:na]
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.mybatis.spring.mapper.MapperScannerConfigurer.<init>()
at java.lang.Class.getConstructor0(DynamicHub.java:3349) ~[na:na]
at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2553) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[na:na]
... 19 common frames omittedpom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fandow</groupId>
<artifactId>oa-staff</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oa-staff</name>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.4.0</spring-boot.version>
<oa-common.version>2.0.0-SNAPSHOT</oa-common.version>
<tomcat-embed-programmatic-version>9.0.38.1-dev</tomcat-embed-programmatic-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.experimental</groupId>
<artifactId>tomcat-embed-programmatic</artifactId>
<version>${tomcat-embed-programmatic-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-graalvm-native</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>com.fandow.framework</groupId>
<artifactId>oa-common-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.fandow.framework</groupId>
<artifactId>oa-common-web</artifactId>
<version>${oa-common.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>20.3.0</version>
<configuration>
<mainClass>com.fandow.oa.OaStaffApplication</mainClass>
<buildArgs>
-Dspring.graal.skip-logback=true
-Dspring.graal.verbose=true
-Dspring.native.remove-yaml-support=true
-Dspring.spel.ignore=true
--trace-class-initialization=org.springframework.util.unit.DataSize
--report-unsupported-elements-at-runtime
--enable-https
-H:+ReportUnsupportedElementsAtRuntime
-H:+AddAllCharsets
--allow-incomplete-classpath
--report-unsupported-elements-at-runtime -H:+ReportExceptionStackTraces
--no-server
-H:IncludeResourceBundles=javax.servlet.http.LocalStrings
-H:IncludeResourceBundles=javax.servlet.LocalStrings
--initialize-at-run-time=io.netty.channel.unix.Socket
--initialize-at-run-time=io.netty.channel.unix.IovArray
--initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop
--initialize-at-run-time=io.netty.channel.unix.Errors
--initialize-at-build-time=org.springframework.util.unit.DataSize
</buildArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<mainClass>com.fandow.oa.OaStaffApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Bootstrap Application
package com.fandow.oa;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
/**
* @version 1.0.0
* @since 2020-12-12
*/
@SpringBootApplication
@Configuration(proxyBeanMethods=false)
@MapperScan("com.fandow.oa.infrastructure.mapper")
public class OaStaffApplication {
public static void main(String[] args) {
SpringApplication.run(OaStaffApplication.class, args);
}
}Error screenshot
What happened?
Plz help me, thx.
Reacted by geekrusice, cuihj and francis
Metadata
Metadata
Assignees
Labels
for: external-projectFor an external project and not something we can fixjvm-reachability-metadataShould be supported via the GraalVM JVM Reachability Metadata Repository once availabletype: compatibilityNative image compatibility issue

Activity
[-]Use mybatisPlus. Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException[/-][+]Used mybatisPlus. Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException[/+][-]Used mybatisPlus. Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException[/-][+]Add MyBatis support[/+]ycfeng commentedon Dec 22, 2020
mybatis-spring-boot-starter not work too.
cuihj commentedon Mar 24, 2021
I ran into the same problem
I ran into the same problem
sk142857 commentedon Nov 2, 2021
the same problem
sdeleuze commentedon Jan 10, 2022
With recent fixes related to MyBatis with Spring Native 0.11, should we claim MyBatis support? If so, I would appreciate a PR with a dedicated sample.
linghengqian commentedon Jan 12, 2022
making commentedon Jan 12, 2022
@kazuki43zoo FYI
kazuki43zoo commentedon Jan 12, 2022
@linghengqian @making Thanks for mention !!
@sdeleuze , @snicoll, and other contributors
I'll try to integrate with spring-native for MyBaits's modules. Many problems have been solved, but I am encountering one problem that cannot be solved yet. I would be grateful if tell me a hint for resolving this issue when you have time.
Once this issue is resolved, I would suggest publishing it as an official module to MyBatis owners.
kazuki43zoo commentedon Jan 31, 2022
Hi guys, The MyBatis team has been published the integration module for spring-native feature to Sonatype OSS repository. Please try it and welcome to feedback!!
sdeleuze commentedon Feb 1, 2022
Nice thanks for working on this.
sdeleuze commentedon Jan 2, 2023
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.
As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the GraalVM Reachability Repository project.
Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.