如何将spring.xml定义的bean自动装配到@Component Beans

时间:2015-10-07 14:04:20

标签: java xml spring spring-mvc

我有一个大型Spring项目,其bean主要通过类上的@Component注释创建。我慢慢地将bean定义移动到spring.xml配置文件。

但是,每当我尝试将在xml配置文件中创建的bean自动装配到通过@Component注释创建的bean中时,我都会收到以下错误。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ComponentBean' defined in class path resource [spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'xmlBean' of bean class [myproject.XmlBean]: Bean property 'xmlBean' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

在我的spring.xml中:

<bean id="xmlBean" class="myproject.XmlBean" />

尝试将bean自动装配到@Component bean中,如下所示:

@Component
class ComponentBean {

    @Autowired
    private XmlBean xmlBean;


    // Bean setters and getters
}

有没有办法让我把这两者定义为两个,因为我慢慢地将我的bean定义移植到spring.xml配置文件。

0 个答案:

没有答案
相关问题