http://blog.csdn.net/w410589502/article/details/51861296
1 使用<context:component-scan />让注解工作起来
base-package 属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理.
<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-
2.5.xsd
$$http://www.springframework.org/schema/context
$$http://www.springframework.org/schema/context/spring-context-
2.5.xsd">
$$<context:component-scan base-package="com.kedacom.ksoa" />
</beans>
2 @Resource 注入属性
@Resource 有两个属性是比较重要的,分别是 name 和 type,默认按 name 匹配.
对成员变量进行标注, Spring 会直接将 UserDao 类型的唯一一个 bean 赋值给 userDao 这
个成员变量
public class UserManagerImpl implements UserManager {
$$@Resource
$$private UserDao userDao;
$$...
}
3 @Repository、@Service、@Controller 完成对 bean 的定义
@ Repository: 存储层 Bean(dao)