问答详情
源自:3-4 Spring Bean装配之自动装配

spring4.3.8 XML文件的bean id与AutoWritingService 的属性完全不对应,也可以执行,为什么?

package BeanAutoWriting;

public class AutoWritingService {
    private AutoWritingDAO autoWritingDAO1;
    
    
    public void setAutoWritingDAO1(AutoWritingDAO autoWritingDAO) {
        System.out.println("执行set方法");
        this.autoWritingDAO1 = autoWritingDAO;
    }


    public void say(String word) {
        this.autoWritingDAO1.say(word);

    }
}




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd"
        default-autowire="byType" >
        
<!--id标识 class权限命名  -->         
<bean id="autoWritingService" class="BeanAutoWriting.AutoWritingService"></bean>
<bean id="autoWriting" class="BeanAutoWriting.AutoWritingDAO"></bean>

</beans>

提问者:快乐不假 2017-04-23 11:18

个回答

  • 快乐不假
    2017-04-23 11:43:23

    搞错了