看到di注入的时候,bean注入注入不进去,(set方法没有被标记)
<bean id="address" class="com.suchangli.pojo.Address">
<property name="address" value="西安"/>
</bean>
<bean id="student" class="com.suchangli.pojo.Student">
<!--第一种,值注入-->
<property name="name" value="苏昌离"/>
<!--第二种,bean注入-->
<property name="address " ref="address"/>
就是第二种注入注入不进去
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'student' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'address ' of bean class [com.suchangli.pojo.Student]: Bean property 'address ' is not writable or has an invalid setter method. Did you mean 'address'?
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
目测多了一个空格,把空格去掉应该就可以了
<property name="address" value="西安"/>
换一下这个参数的name名看下