Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not support spring boot 3 native compile? #776

Open
tullyliu opened this issue Dec 15, 2022 · 31 comments
Open

do not support spring boot 3 native compile? #776

tullyliu opened this issue Dec 15, 2022 · 31 comments
Assignees

Comments

@tullyliu
Copy link

tullyliu commented Dec 15, 2022

using samples code
mybatis-spring-boot-samples/mybatis-spring-boot-sample-web
mvn -Pnative native:compile

when run target/mybatis-spring-boot-sample-web,it has following exceptions.

java.lang.ExceptionInInitializerError: null
        at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:363) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) ~[na:na]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:145) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:745) ~[mybatis-spring-boot-sample-web:6.0.2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[mybatis-spring-boot-sample-web:6.0.2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[mybatis-spring-boot-sample-web:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[mybatis-spring-boot-sample-web:3.0.0]
        at sample.mybatis.web.SampleWebApplication.main(SampleWebApplication.java:25) ~[mybatis-spring-boot-sample-web: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:60) ~[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
@tullyliu tullyliu reopened this Dec 15, 2022
@tullyliu tullyliu changed the title do not support spring boot 3 native ? do not support spring boot 3 native compile? Dec 15, 2022
@Maijh97
Copy link

Maijh97 commented Dec 23, 2022

So have I. Is there any solution?

@gogolin001
Copy link

gogolin001 commented Dec 28, 2022

I have the same problem. How to resolve?

Exception in thread "main" org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it:
        org.apache.ibatis.builder.CacheRefResolver
        org.apache.ibatis.parsing.XNode
        org.apache.ibatis.mapping.ResultFlag
        org.apache.ibatis.builder.ResultMapResolver
        org.apache.ibatis.builder.annotation.MethodResolver

        at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:87)
        at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:70)    
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
        at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
        at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)

@ijry
Copy link

ijry commented Dec 30, 2022

+1

@hazendaz
Copy link
Member

hazendaz commented Dec 30, 2022 via email

@ijry
Copy link

ijry commented Jan 3, 2023

Issue is in mybatis core. We will have to release a patch. Will look more at this in coming days... Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg

________________________________ From: jry @.> Sent: Thursday, December 29, 2022 8:50:26 PM To: mybatis/spring-boot-starter @.> Cc: Subscribed @.> Subject: Re: [mybatis/spring-boot-starter] do not support spring boot 3 native compile? (Issue #776) +1 — Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmybatis%2Fspring-boot-starter%2Fissues%2F776%23issuecomment-1367679678&data=05%7C01%7C%7Ca40e3b91e4044529990a08daea083996%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638079618287463263%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=gzKzbkpftjjdrDUhwPKaVCAm4FXyW8g1aqPxrP2CCFg%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODI7S6H2RBCCFQXAVH7LWPY5WFANCNFSM6AAAAAAS7PY3MI&data=05%7C01%7C%7Ca40e3b91e4044529990a08daea083996%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638079618287463263%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=v6ZbrV3Rnw2bqEVO3%2BtIn1769fK5foq5Uug50AAykLo%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.>

look forward to.

@TKorhonen
Copy link

Any news on this?

@duyucongc
Copy link

duyucongc commented Feb 19, 2023

I register Slf4jImpl and Marker but still have other error

import org.apache.ibatis.logging.slf4j.Slf4jImpl;
import org.slf4j.Marker;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;

@ImportRuntimeHints(CustomerControllerRuntimeHints.class)
public static class CustomerControllerRuntimeHints implements RuntimeHintsRegistrar {

        @Override
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
            hints.reflection().registerType(Slf4jImpl.class, MemberCategory.DECLARED_FIELDS,
                                            MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
                                            MemberCategory.INVOKE_DECLARED_METHODS,
                                            MemberCategory.INVOKE_PUBLIC_METHODS,
                                            MemberCategory.DECLARED_CLASSES);
            hints.reflection().registerType(Marker.class, MemberCategory.DECLARED_FIELDS,
                                            MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
                                            MemberCategory.INVOKE_DECLARED_METHODS,
                                            MemberCategory.INVOKE_PUBLIC_METHODS,
                                            MemberCategory.DECLARED_CLASSES);
        }
    }

but still have ConfigurationClassPostProcessor.init error

@goatherd-bot
Copy link

I have the same problem. How to resolve?

Exception in thread "main" org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it: org.apache.ibatis.builder.CacheRefResolver org.apache.ibatis.parsing.XNode org.apache.ibatis.mapping.ResultFlag org.apache.ibatis.builder.ResultMapResolver org.apache.ibatis.builder.annotation.MethodResolver

    at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:87)
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:70)    
    at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
    at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
    at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
    at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
    at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
    at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
    at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
    at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
    at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)

Would you like to ask if this problem has been solved?This error also occurred when I used native image packaging in spring boot 3

@goatherd-bot
Copy link

Issue is in mybatis core. We will have to release a patch. Will look more at this in coming days... Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg

________________________________ From: jry @.> Sent: Thursday, December 29, 2022 8:50:26 PM To: mybatis/spring-boot-starter @.> Cc: Subscribed @.> Subject: Re: [mybatis/spring-boot-starter] do not support spring boot 3 native compile? (Issue #776) +1 — Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmybatis%2Fspring-boot-starter%2Fissues%2F776%23issuecomment-1367679678&data=05%7C01%7C%7Ca40e3b91e4044529990a08daea083996%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638079618287463263%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=gzKzbkpftjjdrDUhwPKaVCAm4FXyW8g1aqPxrP2CCFg%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODI7S6H2RBCCFQXAVH7LWPY5WFANCNFSM6AAAAAAS7PY3MI&data=05%7C01%7C%7Ca40e3b91e4044529990a08daea083996%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638079618287463263%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=v6ZbrV3Rnw2bqEVO3%2BtIn1769fK5foq5Uug50AAykLo%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.>

Would you like to ask if this problem has been solved?

@hazendaz
Copy link
Member

hazendaz commented Feb 20, 2023 via email

@wghdir
Copy link

wghdir commented Feb 22, 2023

When to released?
Mybatis is very important.

@hazendaz
Copy link
Member

going to try for this coming weekend.

@ijry
Copy link

ijry commented Mar 3, 2023

is a snapshot version can try?

@hazendaz
Copy link
Member

hazendaz commented Mar 3, 2023 via email

@wghdir
Copy link

wghdir commented Mar 4, 2023

Through ImportRuntimeHints, mybatis use @select("select * from xxxx") can run, but if there is use *Mapper.xml, it will prompt Invalid bound statement (not found).

@xiao-er-shang-jiu
Copy link

is there any solution now?

@holmofy
Copy link

holmofy commented Mar 29, 2023

How is this problem progressing now? Do you have any solutions

@hazendaz
Copy link
Member

mybatis 3.5.13 is out at this point, if you override used version to 3.5.13, I think this will be resolved, can someone confirm?

@fabienfleureau
Copy link

fabienfleureau commented Mar 30, 2023

Hello,
I still have the issue with 3.5.13.

Application run failed
j.l.NullPointerException: null
at o.a.i.l.LogFactory.getLog(LogFactory.java:52)
... 15 common frames omitted
Wrapped by: o.a.i.l.LogException: Error creating logger for logger org.mybatis.spring.mapper.ClassPathMapperScanner. Cause: java.lang.NullPointerException
at o.a.i.l.LogFactory.getLog(LogFactory.java:54)
at o.a.i.l.LogFactory.getLog(LogFactory.java:47)
at o.m.l.LoggerFactory.getLogger(LoggerFactory.java:32)
at o.m.s.m.ClassPathMapperScanner.(ClassPathMapperScanner.java:61)
... 12 common frames omitted
Wrapped by: j.l.ExceptionInInitializerError: null
at o.m.s.m.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:363)
at o.s.c.s.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344)
at o.s.c.s.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:145)
at o.s.c.s.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:747)
at o.s.c.s.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565)
at o.s.b.w.s.c.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at o.s.b.SpringApplication.refresh(SpringApplication.java:732)
at o.s.b.SpringApplication.refreshContext(SpringApplication.java:434)
at o.s.b.SpringApplication.run(SpringApplication.java:310)
at o.s.b.SpringApplication.run(SpringApplication.java:1304)
at o.s.b.SpringApplication.run(SpringApplication.java:1293)
at c.m.m.f.r.Application.main(Application.java:13)

@a483210
Copy link

a483210 commented Apr 3, 2023

Hello,
I did not find graalvm related file configuration under mybatis3 related library. Has it not yet prepared for compatibility with native?

@goatherd-bot
Copy link

goatherd-bot commented Apr 4, 2023

After using 3.5.13 and running exe after packaging, the following error still occurs
If running locally, there is no problem, but there will be an error when running as an exe

`
org.springframework.boot
spring-boot-starter-parent
3.0.0

<groupId>com.XXX.graalvm</groupId>
<artifactId>demo-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <java.version>17</java.version>
</properties>
<dependencies>

    <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>3.0.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.13</version>
    </dependency>`

@Mapper public interface StoreSceneMapper{ @Select("select * from t_store_scene where scene_id = #{id}") StoreSceneDo getStoreById(@Param(value = "id") String id); }

java.lang.ExceptionInInitializerError: null
        at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:363) ~[demo-mybatis.exe:3.0.1]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) ~[na:na]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:145) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:745) ~[demo-mybatis.exe:6.0.2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[demo-mybatis.exe:6.0.2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[demo-mybatis.exe:3.0.0]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[demo-mybatis.exe:3.0.0]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[demo-mybatis.exe:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[demo-mybatis.exe:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[demo-mybatis.exe:3.0.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[demo-mybatis.exe:3.0.0]
        at com.jlpay.graalvm.BootstrapApplication.main(BootstrapApplication.java:18) ~[demo-mybatis.exe: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:61) ~[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

@goatherd-bot
Copy link

If it is solved according to what you said, could you please attach a demo for me to learn how to do it? thank you

@BlueSkyT
Copy link

BlueSkyT commented Apr 4, 2023

After using 3.5.13 and running exe after packaging, the following error still occurs If running locally, there is no problem, but there will be an error when running as an exe

` org.springframework.boot spring-boot-starter-parent 3.0.0

<groupId>com.XXX.graalvm</groupId>
<artifactId>demo-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <java.version>17</java.version>
</properties>
<dependencies>

    <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>3.0.1</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.5.13</version>
    </dependency>`

@Mapper public interface StoreSceneMapper{ @Select("select * from t_store_scene where scene_id = #{id}") StoreSceneDo getStoreById(@Param(value = "id") String id); }

java.lang.ExceptionInInitializerError: null at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:363) ~[demo-mybatis.exe:3.0.1] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) ~[na:na] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:145) ~[na:na] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:745) ~[demo-mybatis.exe:6.0.2] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[demo-mybatis.exe:6.0.2] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[demo-mybatis.exe:3.0.0] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[demo-mybatis.exe:3.0.0] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[demo-mybatis.exe:3.0.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[demo-mybatis.exe:3.0.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[demo-mybatis.exe:3.0.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[demo-mybatis.exe:3.0.0] at com.jlpay.graalvm.BootstrapApplication.main(BootstrapApplication.java:18) ~[demo-mybatis.exe: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.(ClassPathMapperScanner.java:61) ~[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

I have the same problem. How to resolve?

@fabienfleureau
Copy link

fabienfleureau commented Apr 6, 2023

Hello,

I tried with a HintsRegistrar inspired from Josh Long blog

import java.util.function.Consumer;
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
import org.apache.ibatis.javassist.util.proxy.RuntimeSupport;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.logging.log4j.Log4jImpl;
import org.apache.ibatis.logging.log4j2.Log4j2Impl;
import org.apache.ibatis.logging.nologging.NoLoggingImpl;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.logging.Logger;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;

public class MyBatisHintsRegistrar implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
        Consumer<TypeHint.Builder> memberCategoryBuilder = builder -> builder.withMembers(
                MemberCategory.INVOKE_PUBLIC_METHODS,
                MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS,
                MemberCategory.PUBLIC_CLASSES,
                MemberCategory.PUBLIC_FIELDS,
                MemberCategory.DECLARED_CLASSES,
                MemberCategory.DECLARED_FIELDS,
                MemberCategory.INTROSPECT_DECLARED_METHODS,
                MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS
                );
        hints
                .reflection()
                .registerType(MyMapper.class, memberCategoryBuilder)
                .registerType(Logger.class, memberCategoryBuilder)
                .registerType(LogFactory.class, memberCategoryBuilder)
                .registerType(XMLLanguageDriver.class, memberCategoryBuilder)
                .registerType(RuntimeSupport.class, memberCategoryBuilder)
                .registerType(ProxyFactory.class, memberCategoryBuilder)
                .registerType(Log.class, memberCategoryBuilder)
                .registerType(StdOutImpl.class, memberCategoryBuilder)
                .registerType(NoLoggingImpl.class, memberCategoryBuilder)
                .registerType(NoLoggingImpl.class, memberCategoryBuilder)
                .registerType(NoLoggingImpl.class, memberCategoryBuilder)
                .registerType(SqlSessionTemplate.class, memberCategoryBuilder)
                .registerType(SqlSessionFactory.class, memberCategoryBuilder)
                .registerType(SqlSessionFactoryBean.class, memberCategoryBuilder)
                .registerType(Log4jImpl.class, memberCategoryBuilder)
                .registerType(Log4j2Impl.class, memberCategoryBuilder)
                .registerType(org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl.class, memberCategoryBuilder);
        hints
                .proxies()
                .registerJdkProxy(MyMapper.class);
    }
}

and a src/main/resources/META-INF/spring/aot.factories configuration file:
org.springframework.aot.hint.RuntimeHintsRegistrar=mypackage.MyBatisHintsRegistrar

With the previous configuration the error disappear but I have another error at during the mapper instanciation:
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"

@cadb-craftsman
Copy link

Hi, I found a method to generate functional native image, I followed all recomendations but after that I always with the same result. The main problem is the NullpointerException when generate SqlSessionFactory and SqlSessionTemplate because the class LoggerFactory cannot instantiate, I didn't fount the solution for that, I downloaded the source of mybatis starter code and I had to comment the lines of log of the classes:

SqlSessionFactoryBean
SqlSessionUtils
MyBatisBatchItemWriter
ClassPathMapperScanner
SpringManagedTransaction

After that I generated a new SNAPSHOT of mybatis starter, I had to create SqlSessionFactory and SqlSessionTemplate in config class and finally I can instantiate a MyBatis Mapper class.

The code is in this repository

https://github.com/cadb-craftsman/springboot-labs.git

https://github.com/cadb-craftsman/springboot-labs/tree/main/catalogsvc

The native image is in docker hub:

https://hub.docker.com/repository/docker/cadbcraftsman/catalogsvc/general

This only works with mybatis annotation classes

@kazuki43zoo
Copy link
Member

I provide a small example for Native image using Spring Boot 3 and MyBatis.

https://github.com/kazuki43zoo/mybatis-native-demo

We will be support the Spring Native(AOT) on https://github.com/mybatis/spring-native , please wait few time!!

@kazuki43zoo
Copy link
Member

I added the Quick start page in Wiki

@kazuki43zoo kazuki43zoo added this to the General Backlog milestone May 13, 2023
@kazuki43zoo kazuki43zoo self-assigned this May 13, 2023
@kazuki43zoo kazuki43zoo pinned this issue May 13, 2023
@kdldbq
Copy link

kdldbq commented Jul 6, 2023

I provide a small example for Native image using Spring Boot 3 and MyBatis.

https://github.com/kazuki43zoo/mybatis-native-demo

We will be support the Spring Native(AOT) on https://github.com/mybatis/spring-native , please wait few time!!

It's useful to make my microserivce projects build successfully. The two point I get from this project:

  1. @MapperScan must be declare sqlSessionTemplateRef property;
  2. Copy MyBatisNativeConfiguration into project.

I do appreciate it.

@yangmy666
Copy link

GraalVM Native Image: Generating 'mybatis-native-sample' (executable)...

Warning: Method com.zaxxer.hikari.HikariConfig.getScheduledExecutorService() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.isInitializationFailFast() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.isJdbc4ConnectionTest() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setInitializationFailFast(boolean) not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setJdbc4ConnectionTest(boolean) not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setScheduledExecutorService(ScheduledThreadPoolExecutor) not found.

@TKorhonen
Copy link

So what is the current situation of a real Spring native support?

@joshlong
Copy link
Contributor

joshlong commented Nov 1, 2023

I am not affiliated with the project, I am just a big fan, and I wanted this support, so I put something together here [1] as an example. I would love it if Mybatis incorporated it into the project officially. I've put the example and the auto-config in one folder, but obviously the auto-config should live in its own .jar.

this builds upon some of the excellent work @kazuki43zoo has done

if the starter is not ready to support Spring Boot 3 exclusively, maybe it could go in a spring-aot module?

  1. https://github.com/joshlong/mybatis-and-spring-boot-3-aot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests