簡體   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