sping 注解,bean属性 学习

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

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

心得:看会了不是你的,理解了、用过了才是你的。

 

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@Autowired注解与自动装配

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

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

 或者用这个

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值