mybatis / spring-boot-starter

MyBatis integration with Spring Boot
Apache License 2.0
4.12k stars 1.79k forks source link

do not support spring boot 3 native compile? #776

Open tullyliu opened 1 year ago

tullyliu commented 1 year ago

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
Maijh97 commented 1 year ago

So have I. Is there any solution?

gogolin001 commented 1 year ago

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 commented 1 year ago

+1

hazendaz commented 1 year ago

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

ijry commented 1 year ago

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 commented 1 year ago

Any news on this?

duyucongc commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Sorry hasn't been resolved yet. It will be fixed in mybatis 3.5.12. We haven't released it yet.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: goatherd-bot @.> Sent: Monday, February 20, 2023 1:35:14 AM To: mybatis/spring-boot-starter @.> Cc: Jeremy Landis @.>; Comment @.> Subject: Re: [mybatis/spring-boot-starter] do not support spring boot 3 native compile? (Issue #776)

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/AAb9ysghttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2FAAb9ysg&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186700764%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TLqVHlWOH9XfPB7Gc4jfLsJxvkbpkOzpvVXwlXhbORQ%3D&reserved=0____ 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 #776https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmybatis%2Fspring-boot-starter%2Fissues%2F776&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186857001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2jqiCqgLOOW8vfsBisNLeqD5gYbGWmHQ6tLPufBSP70%3D&reserved=0) +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=0https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmybatis%2Fspring-boot-starter%2Fissues%2F776%23issuecomment-1367679678&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186857001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TKYRQ39XDzFbwXTWR%2FVQHb5yU%2F9Z7TfW6CVpk5cBXks%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=0https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODI7S6H2RBCCFQXAVH7LWPY5WFANCNFSM6AAAAAAS7PY3MI&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186857001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=MsbhlDYJ0yswz88k5mS81EbMbH4H4t%2BWGYlIqtxeyo4%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?

— 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-1436406739&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186857001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TtqtSlIGa8UY0PsJoP7ZQSGnmqCm09OByX7Tpm79N84%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODI53XADJGUPOC7WU2NDWYMGCFANCNFSM6AAAAAAS7PY3MI&data=05%7C01%7C%7C466050d8cd3944336dd108db130ca031%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638124717186857001%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OqgnQ1EtvISG%2B3HrrH3jTX1KAXK2LL38B4SrhTC%2BvdQ%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

wghdir commented 1 year ago

When to released? Mybatis is very important.

hazendaz commented 1 year ago

going to try for this coming weekend.

ijry commented 1 year ago

is a snapshot version can try?

hazendaz commented 1 year ago

We released 3.5 12 but it has a bad regression. Intended to get it out again tonight but something came up. However expect all of this to be addressed this weekend. Feel free to try the 3.5.12 to just see if the specific issue goes away but know it has issues. See our issue tracker on the core to see the recession. Sorry for the trouble this is otherwise causing.

Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jry @.> Sent: Thursday, March 2, 2023 8:05:46 PM To: mybatis/spring-boot-starter @.> Cc: Jeremy Landis @.>; Comment @.> Subject: Re: [mybatis/spring-boot-starter] do not support spring boot 3 native compile? (Issue #776)

is a snapshot version can try?

— 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-1452789205&data=05%7C01%7C%7Ccb25a489ce424642ccfb08db1b836bb7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638134023489160246%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6aZYDwtUxkXeREDdoKshZJaDt7pTHtgxje2BctPskTg%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAHODI7XQ6YTV6LYAX63E6DW2E7WVANCNFSM6AAAAAAS7PY3MI&data=05%7C01%7C%7Ccb25a489ce424642ccfb08db1b836bb7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638134023489160246%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7rdtuzJDQ10ZsbVzndgnW3BrEwyxKPCScyImT9rUFZ4%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>

wghdir commented 1 year ago

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 commented 1 year ago

is there any solution now?

holmofy commented 1 year ago

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

hazendaz commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

goatherd-bot commented 1 year ago

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
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.0</version>
    <!-- lookup parent from repository -->
</parent>

<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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I added the Quick start page in Wiki

kdldbq commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

joshlong commented 10 months ago

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
Master-Cao commented 1 month ago

hello, is this problem resolved? or there has any temporary solution?

iloveuaa commented 1 month ago

wait...

xuxiaowei-com-cn commented 1 month ago

Completed debugging of MyBatis functionality for Spring Boot 3.

Please refer to the submission record of the mybatis/native-image branch for details.

https://github.com/xuxiaowei-com-cn/spring-cloud-graalvm

xuxiaowei-com-cn commented 1 month ago

:sparkles: Support MyBatis for Spring Boot 3 Native: https://github.com/mybatis/spring-boot-starter/issues/994