简体   繁体   中英

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

I have the following bean definitions in the application context XML:

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

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

When I run the code:

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

It displays fine, that is, "testing". BUT, when I make the helloWorld bean implement BeanPostProcessor then the value of message bean becomes null. Is this a bug?

Ok, found the problem. The 2 methods of the BeanPostProcessor must return the first argument. Instead I was returning null. I found the answer here: I am using bean post processor, and it is giving null pointer exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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