自动装配方式分为:no、byName、byType、constructor四种,默认为no
package com.bebig.service;

import com.bebig.dao.UserDAO;
import com.bebig.model.User;
//逻辑业务层
public class UserService {
    
private UserDAO userDAO;

    
public void add(User u) {
        userDAO.save(u);

    }


    
public void setUserDAO(UserDAO userDAO) {
        
this.userDAO = userDAO;
    }


    
public UserDAO getUserDAO() {
        
return userDAO;
    }

}

beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation
="
http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"

    <!-- 指定本beans里所有bean的默认自动装配方式 --
>
    default-autowire="byName">

    
<!-- a service object; we will be profiling its methods -->

    
<bean name="userDAO" class="com.bebig.dao.impl.UserDAOImpl">
        
<property name="daoId" value="1"></property>
    
</bean>
    
    
<bean name="u2" class="com.bebig.dao.impl.UserDAOImpl">
        
<property name="daoId" value="1"></property>
    
</bean>
    
<!-- 按指定方式装配 -->
    
<bean id="userService" class="com.bebig.service.UserService"
        scope
="prototype" autowire="byType">
    
</bean>

</beans>