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

@EnableNacosDiscovery 注解不生效 #261

Open
QBH-insist opened this issue Jun 7, 2021 · 0 comments
Open

@EnableNacosDiscovery 注解不生效 #261

QBH-insist opened this issue Jun 7, 2021 · 0 comments

Comments

@QBH-insist
Copy link

QBH-insist commented Jun 7, 2021

Issue Description

Type: bug report
@EnableNacosDiscovery 不生效,现象是:@import 注解的 NacosDiscoveryBeanDefinitionRegistrar 的 registerBeanDefinitions 方法 不能被执行,
服务注册发现失效

Describe what happened (or what feature you want)

在我司的一个老项目中(javaweb)中,使用 https://nacos.io/zh-cn/docs/quick-start-spring.html 教程进行接入 nacos,
发现并不能如期进行服务注册和发现,且注入 NamingService 失败
image

Describe what you expected to happen

期望在 spring 4.x 环境能支持 nacos-spring-context

How to reproduce it (as minimally and precisely as possible)

Nacos 配置类
image

测试 Controller 类
image

Tell us your environment

nacos-spring-context:1.1.0
spring-core/context/web/webmvc:4.3.18.RELEASE

Anything else we need to know?

在发现这种情况的时候我进行了 debug
1.debug 确认了 NacosDiscoveryBeanDefinitionRegistrar 的 setEnvironment hook 方法是正常被调用
2.debug 确认了 NacosDiscoveryBeanDefinitionRegistrar 的 registerBeanDefinitions hook 方法是没有被调用
3.对第二点进行更进一步的 debug:
ConfigurationClassParser 的 doProcessConfigurationClass 会对配置类的注解进行处理,里面包括扫描 @import 注解进行处理的逻辑。
跟进 doProcessConfigurationClass 方法 processImports 流程 的 getImports 方法
image
最后发现在对 @EnableNacosDiscovery 进行扫描内部注解时出现了异常,但是异常被 spring 忽略了,直接导致没有对 @import 注解进行相对应的处理。
image
image
image

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

1 participant