nacos-group / nacos-spring-project

Nacos ECO Project for Spring Framework
https://nacos.io/
Apache License 2.0
754 stars 309 forks source link

nacos 监听refresh Event 事件导致lazyInit Bean提前加载 #299

Open huyiyu opened 1 year ago

huyiyu commented 1 year ago

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

我使用了 nacos-spring-boot-starter 引入了nacos-spring-context 1.1.1 部分需要lazyInit 的对象在 nacos 判断 NacosConfigListener 注解是否存在的接口上出现,具体代码 getBeanOfType方法 此处getBean导致了所有Bean都被迫创建,建议改造成 getBeanNameOfType 以及 getType 方式获取Bean的类型,这样不会加载到不应该被提前加载的累

Describe what you expected to happen

希望 @Lazy 注解相关的内容不在此处创建(外部对接服务)

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

  1. 为一个bean设置@Lazy
  2. 观察是否在nacos 接收到spring 启动成功事件时 被放入BeanMap 变量。

    Tell us your environment

    • nacos-spirng-boot-starter 0.2.12
    • jdk 8
    • windows 10

      Anything else we need to know?

      对于注解的扫描可以不必调用getBean ,直到确实有存在注解才去getBean 因为getBean方法在对象没有的时候会走创建逻辑

huyiyu commented 1 year ago

解决方案想提个pr