---
title: "sping 注解，bean属性\u3000学习"
author: "Eric.Yan"
date: "2013-07-18T14:38:51Z"
tags: []
categories: ["企业架构"]
slug: "sping-bean"
draft: false
lastmod: "2013-07-18T14:38:51Z"
id: 1909227
url: "https://eric-yan.iteye.com/blog/1909227"
---

项目开发告一段落，就静下心来看看前人写的代码，遇不懂或疑惑之处，便翻阅字典，

看罢，哦…………原来是这样，不禁叹声，于是作为札记以记录，以便日后所用。

**心得：看会了不是你的，理解了、用过了才是你的。**

 

[Spring注解@Component、@Repository、@Service、@Controller区别](http://blog.csdn.net/zhang854429783/article/details/6785574)

总结：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属性配置](http://blog.csdn.net/bruce_sky/article/details/7505648)**parent**   表示该Bean为子Bean，其值指向父Bean，重用父Bean已实现的依赖

**singleton属性值**指定此Java Bean是否采用单例（Singleton）模式 ,默认true;

 

[Spring@Autowired注解与自动装配](http://blog.csdn.net/heyutao007/article/details/5981555)

Spring 通过一个 BeanPostProcessor 对 @Autowired 进行解析，所以要让 @Autowired 起作用必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean;

```
 <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
```

 或者用这个

```
<!-- Activates scanning of @Autowired -->
<context:annotation-config />
```