Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Add MyBatis support #404

Closed as not planned
Closed as not planned

Description

@geekrusice

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 omitted

pom.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

Snipaste_2020-12-12_21-32-53

What happened?
Plz help me, thx.

Activity

  1. changed the title [-]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[/+] on Dec 12, 2020
  2. changed the title [-]Used mybatisPlus. Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException[/-] [+]Add MyBatis support[/+] on Dec 15, 2020
  3. added
    status: waiting-for-triage
    on Dec 15, 2020
  4. ycfeng commented on Dec 22, 2020

    @ycfeng
    <dependency>
          <groupId>org.mybatis.spring.boot</groupId>
          <artifactId>mybatis-spring-boot-starter</artifactId>
          <version>2.1.4</version>
    </dependency>

    mybatis-spring-boot-starter not work too.

  5. cuihj commented on Mar 24, 2021

    @cuihj

    I ran into the same problem

    <dependency>
          <groupId>org.mybatis.spring.boot</groupId>
          <artifactId>mybatis-spring-boot-starter</artifactId>
          <version>2.1.4</version>
    </dependency>
    

    mybatis-spring-boot-starter not work too.

    I ran into the same problem

  6. removed
    status: waiting-for-triage
    on Mar 29, 2021
  7. added this to the milestone on Mar 29, 2021
  8. added
    type: compatibility
    on Mar 29, 2021
  9. sk142857 commented on Nov 2, 2021

    @sk142857
    2021-11-02 14:56:27.857  INFO 1 --- [           main] o.s.nativex.NativeListener               : This application is bootstrapped with code generated with Spring AOT,
    2021-11-02 14:56:27.867  INFO 1 --- [           main] o.s.nativex.NativeListener               : This application is bootstrapped with code generated with Spring AOT,
    ,
      .   ____          _            __ _ _,
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \,
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \,
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) ),
      '  |____| .__|_| |_|_| |_\__, | / / / /,
     =========|_|==============|___/=/_/_/_/,
     :: Spring Boot ::                (v2.5.6),
    ,
    2021-11-02 14:56:27.868  INFO 1 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default,
    2021-11-02 14:56:27.922 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed,
    ,
    java.lang.ExceptionInInitializerError: null,
    	at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:357) ~[com.example.demo.DemoApplication:2.0.6],
    	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[na:na],
    	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:142) ~[na:na],
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[na:na],
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[na:na],
    	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na],
    	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[com.example.demo.DemoApplication:2.5.6],
    	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[com.example.demo.DemoApplication:2.5.6],
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[com.example.demo.DemoApplication:2.5.6],
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[com.example.demo.DemoApplication:2.5.6],
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[com.example.demo.DemoApplication:2.5.6],
    	at com.example.demo.DemoApplication.main(DemoApplication.java:11) ~[com.example.demo.DemoApplication:na],
    Caused by: org.apache.ibatis.logging.LogException: Error creating logger for logger org.mybatis.spring.mapper.ClassPathMapperScanner.  Cause: java.lang.NullPointerException,
    	at org.apache.ibatis.logging.LogFactory.getLog(LogFactory.java:54) ~[na:na],
    	at org.apache.ibatis.logging.LogFactory.getLog(LogFactory.java:47) ~[na:na],
    	at org.mybatis.logging.LoggerFactory.getLogger(LoggerFactory.java:32) ~[na:na],
    	at org.mybatis.spring.mapper.ClassPathMapperScanner.<clinit>(ClassPathMapperScanner.java:58) ~[na:na],
    	... 12 common frames omitted,
    Caused by: java.lang.NullPointerException: null,
    	at org.apache.ibatis.logging.LogFactory.getLog(LogFactory.java:52) ~[na:na],
    	... 15 common frames omitted,
    
    
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<version>8.0.27</version>
    		</dependency>
    
    		<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
    		<dependency>
    			<groupId>com.baomidou</groupId>
    			<artifactId>mybatis-plus-boot-starter</artifactId>
    			<version>3.4.3.4</version>
    		</dependency>
    
    		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    		<dependency>
    			<groupId>org.projectlombok</groupId>
    			<artifactId>lombok</artifactId>
    			<version>1.18.22</version>
    			<scope>provided</scope>
    		</dependency>
    

    the same problem

  10. sdeleuze commented on Jan 10, 2022

    @sdeleuze
    Contributor

    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.

  11. linghengqian commented on Jan 12, 2022

    @linghengqian

    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.

  12. making commented on Jan 12, 2022

    @making
  13. kazuki43zoo commented on Jan 12, 2022

    @kazuki43zoo
    Contributor

    @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.

  14. kazuki43zoo commented on Jan 31, 2022

    @kazuki43zoo
    Contributor

    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!!

  15. sdeleuze commented on Feb 1, 2022

    @sdeleuze
    Contributor

    Nice thanks for working on this.

  16. added
    jvm-reachability-metadata
    on Mar 17, 2022
  17. sdeleuze commented on Jan 2, 2023

    @sdeleuze
    Contributor

    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.

  18. removed this from the milestone on Jan 2, 2023
  19. added
    for: external-project
    on Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectjvm-reachability-metadatatype: compatibility

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions