项目开发告一段落,就静下心来看看前人写的代码,遇不懂或疑惑之处,便翻阅字典,
看罢,哦…………原来是这样,不禁叹声,于是作为札记以记录,以便日后所用。
心得:看会了不是你的,理解了、用过了才是你的。
Spring注解@Component、@Repository、@Service、@Controller区别
总结:component通用,其他3个精细用,分别对应MVC中的mc,配置让你生效
<context:annotation-config /> <context:component-scan base-package=”com.eric.spring”> <context:include-filter type="regex" expression=".*DaoImpl"/> <context:include-filter type="regex" expression=".*ServiceImpl"/> </context:component-scan>
Spring的bean属性配置parent 表示该Bean为子Bean,其值指向父Bean,重用父Bean已实现的依赖
singleton属性值指定此Java Bean是否采用单例(Singleton)模式 ,默认true;
Spring 通过一个 BeanPostProcessor 对 @Autowired 进行解析,所以要让 @Autowired 起作用必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean;
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
或者用这个
<!-- Activates scanning of @Autowired --> <context:annotation-config />