简体   繁体   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

I have the following bean definitions in the application context XML: 我在应用程序上下文XML中具有以下bean定义:

<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. 但是,当我使helloWorld bean实现BeanPostProcessor时, message bean的值将为null。 Is this a bug? 这是错误吗?

Ok, found the problem. 好的,找到了问题。 The 2 methods of the BeanPostProcessor must return the first argument. BeanPostProcessor的2个方法必须返回第一个参数。 Instead I was returning null. 相反,我返回的是null。 I found the answer here: I am using bean post processor, and it is giving null pointer exception 我在这里找到了答案: 我正在使用Bean后处理器,并且给出了空指针异常

暂无
暂无

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

相关问题 Spring设置java.io.File属性使用java.lang.String bean - Spring set java.io.File property use java.lang.String bean spring 中没有“java.lang.string”类型的合格 bean 可用错误 - no qualifying bean of type 'java.lang.string' available error in spring 尝试使用 Spring 验证请求正文时,“bean 类 [java.lang.String] 的属性‘ssn’无效” - "Invalid property 'ssn' of bean class [java.lang.String]" when trying to validate request body with Spring 无法设置JSTL用户变量而不是java.lang.String - Cannot set JSTL User variable instead of java.lang.String 调用EJB Bean方法时,不能将java.lang.Class强制转换为java.lang.String - java.lang.Class cannot be cast to java.lang.String when invoking a EJB Bean Method 将参数传递给Bean时,没有找到依赖项的类型为[java.lang.String]的合格Bean - No qualifying bean of type [java.lang.String] found for dependency when pass parameter to the Bean 无法解析“查询(java.lang.String,java.lang.String [],null,null,null,null)” - Cannot resolve 'query(java.lang.String,java.lang.String[],null, null, null, null)' java.lang.String的Spring实例化异常 - Spring Instantiation exception with java.lang.String java.lang.illegalargumentexception 无法将 java.lang.string 字段设置为 java.lang.String - java.lang.illegalargumentexception cannot set java.lang.string field to java.lang.String 类需要一个找不到的“java.lang.String”类型的 bean - Class required a bean of type 'java.lang.String' that could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM