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-context仅支持spring 3.2.18及以上版本 #153

Closed
coderDylan opened this issue Sep 20, 2019 · 6 comments
Closed
Labels
Milestone

Comments

@coderDylan
Copy link
Contributor

@Import(NacosConfigBeanDefinitionRegistrar.class)
在NacosConfigBeanDefinitionRegistrar中实现了EnvironmentAware接口,需要调用setEnvironment方法获取到spring 抽象的环境信息。这个在nacos-spring-context项目官方提供的例子中是OK的,例子中使用的是3.2.18版本。
但是,在我们旧项目使用的spring 3.2.5版本(由于种种原因不能轻易升级spring版本),在debug过程中发现setEnvironment方法不会被调用的,所以会导致registerBeanDefinitions方法往下执行会最终引发NPE...
通过debug和对比spring 3.2.5和spring3.2.18的源代码,发现了一些差异和造成该问题的原因

3 2 5
Uploading 3.2.18.jpeg…

@coderDylan
Copy link
Contributor Author

3 2 18

@chuntaojun
Copy link
Member

Thank you for your care

@coderDylan
Copy link
Contributor Author

 @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
        //fix spring3.2.5 bug(该版本不会invoke setEnvironment方法,会导致environment属性为null,registerBeanDefinitions方法最终执行会发生NPE)
        this.environment = beanFactory.getBean(Environment.class);
    }

setBeanFactory方法是正常被invoke的,所以可以这样变现的解决environment属性为null的问题。

不过spring 3.2.5下面还会有其他的问题,由于依赖了alibaba的spring-context-support包,
该包下的AnnotationInjectedBeanPostProcessor#findInjectionMetadata方法中会执行InjectionMetadata#needsRefresh方法会产生NoSuchMethodError,
在spring 3.2.5中InjectionMetadata根本没有needsRefresh方法

@chuntaojun chuntaojun added question Further information is requested Good Tip and removed question Further information is requested labels Oct 25, 2019
@mercyblitz
Copy link
Contributor

mercyblitz commented Dec 10, 2019

Great Job~ You'd better to update Spring framework to be 4.0 and above~

@mercyblitz mercyblitz pinned this issue Dec 10, 2019
@SmileTower
Copy link

spring-context-support version is old, dubbo 2.7.6 this version 1.0.6

@mercyblitz
Copy link
Contributor

version

Updated in the new version.

@mercyblitz mercyblitz added this to the 1.0.0 milestone Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants