繁体   English   中英

当另一个BeanPostProcessor时,Spring bean java.lang.String设置为null,而不是提供的字符串

[英]Spring bean java.lang.String gets set to null instead of the provided string when another BeanPostProcessor

我在应用程序上下文XML中具有以下bean定义:

<bean id="helloWorld" class="com.packt.lifecycle.HelloWorld">
</bean>

<bean name="message" class="java.lang.String">
   <constructor-arg value="testing" />
</bean>

当我运行代码时:

AbstractApplicationContext  context = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println(context.getBean("message"));

它显示正常,即“测试”。 但是,当我使helloWorld bean实现BeanPostProcessor时, message bean的值将为null。 这是错误吗?

好的,找到了问题。 BeanPostProcessor的2个方法必须返回第一个参数。 相反,我返回的是null。 我在这里找到了答案: 我正在使用Bean后处理器,并且给出了空指针异常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM