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

nacos不支持spring native #9085

Closed
xuanyangyang opened this issue Sep 3, 2022 · 6 comments · Fixed by #10634
Closed

nacos不支持spring native #9085

xuanyangyang opened this issue Sep 3, 2022 · 6 comments · Fixed by #10634
Assignees
Labels
area/Spring Boot Related to Spring Boot kind/feature type/feature

Comments

@xuanyangyang
Copy link

xuanyangyang commented Sep 3, 2022

问题
spring native 打包后@NacosInjected没有进行注入,导致产生NullPointerException
异常堆栈如下

2022-09-03 11:23:23.981  INFO 1 --- [           main] c.a.b.n.c.u.NacosConfigPropertiesUtils   : nacosConfigProperties : NacosConfigProperties{serverAddr='localhost:8848', contextPath='null', encode='null', endpoint='null', namespace='null', accessKey='null', secretKey='null', ramRoleName='null', autoRefresh=false, dataId='null', dataIds='null', group='DEFAULT_GROUP', type=PROPERTIES, maxRetry='null', configLongPollTimeout='null', configRetryTime='null', enableRemoteSyncConfig=false, extConfig=[], bootstrap=Bootstrap{enable=false, logEnable=false}}
2022-09-03 11:23:23.981  INFO 1 --- [           main] o.s.nativex.NativeListener               : AOT mode enabled

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.1)

2022-09-03 11:23:23.982  INFO 1 --- [           main] c.a.b.n.c.u.NacosConfigPropertiesUtils   : nacosConfigProperties : NacosConfigProperties{serverAddr='localhost:8848', contextPath='null', encode='null', endpoint='null', namespace='null', accessKey='null', secretKey='null', ramRoleName='null', autoRefresh=false, dataId='null', dataIds='null', group='DEFAULT_GROUP', type=PROPERTIES, maxRetry='null', configLongPollTimeout='null', configRetryTime='null', enableRemoteSyncConfig=false, extConfig=[], bootstrap=Bootstrap{enable=false, logEnable=false}}
2022-09-03 11:23:23.982  INFO 1 --- [           main] NacosConfigApplicationContextInitializer : [Nacos Config Boot] : The preload configuration is not enabled
2022-09-03 11:23:23.982  INFO 1 --- [           main] c.e.nativedemo.NativeDemoApplication     : Starting NativeDemoApplication using Java 17.0.4.1 on 343867af6298 with PID 1 (/workspace/com.example.nativedemo.NativeDemoApplication started by cnb in /workspace)
2022-09-03 11:23:23.982  INFO 1 --- [           main] c.e.nativedemo.NativeDemoApplication     : No active profile set, falling back to 1 default profile: "default"
2022-09-03 11:23:23.995  WARN 1 --- [           main] .r.c.ReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'discoveryController': Invocation of init method failed; nested exception is java.lang.NullPointerException
2022-09-03 11:23:23.995  INFO 1 --- [           main] .c.NacosValueAnnotationBeanPostProcessor : class com.alibaba.nacos.spring.context.annotation.config.NacosValueAnnotationBeanPostProcessor was destroying!
2022-09-03 11:23:23.995  INFO 1 --- [           main] AnnotationNacosInjectedBeanPostProcessor : class com.alibaba.nacos.spring.beans.factory.annotation.AnnotationNacosInjectedBeanPostProcessor was destroying!
2022-09-03 11:23:23.995 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'discoveryController': Invocation of init method failed; nested exception is java.lang.NullPointerException
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[com.example.nativedemo.NativeDemoApplication:2.7.1]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[com.example.nativedemo.NativeDemoApplication:na]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[com.example.nativedemo.NativeDemoApplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[com.example.nativedemo.NativeDemoApplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[com.example.nativedemo.NativeDemoApplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[com.example.nativedemo.NativeDemoApplication:na]
        at com.example.nativedemo.NativeDemoApplication.main(NativeDemoApplication.java:10) ~[com.example.nativedemo.NativeDemoApplication:na]
Caused by: java.lang.NullPointerException: null
        at com.example.nativedemo.DiscoveryController.afterPropertiesSet(DiscoveryController.java:35) ~[com.example.nativedemo.NativeDemoApplication:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[com.example.nativedemo.NativeDemoApplication:5.3.21]
        ... 16 common frames omitted

代码如下
image

环境
Version info: 'GraalVM 22.2.0 Java 17 CE'
Java version info: '17.0.4+8-jvmci-22.2-b06'
spring boot version:2.7.1
spring native version:0.12.1
nacos spring boot version:0.2.12
maven version:3.8.4
docker version:20.10.17
复现步骤
demo仓库:https://github.com/xuanyangyang/native-demo
注意:修改一下application.properties里的nacos配置去适配你的环境

  1. git clone https://github.com/xuanyangyang/native-demo.git
  2. cd native-demo
  3. mvn spring-boot:build-image
  4. docker run --rm -p 10000:10000 --name native-demo native-demo:0.0.1-SNAPSHOT
@KomachiSion KomachiSion added status/invalid This doesn't seem right kind/feature type/feature area/Spring Boot Related to Spring Boot and removed status/invalid This doesn't seem right labels Sep 6, 2022
@sk142857
Copy link

解决了吗?好像还是报错。

@xuanyangyang
Copy link
Author

解决了吗?好像还是报错。

还没解决

@enderwsp
Copy link

nacos-config,包括relfections根据包路径扫描类在native模式下不支持

@linghengqian
Copy link

@onexuan
Copy link

onexuan commented Feb 23, 2023

同样遇到这个问题,@NacosInjected 无效

@DarrenLuo
Copy link
Contributor

@i will solve it@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Spring Boot Related to Spring Boot kind/feature type/feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants