zoukankan      html  css  js  c++  java
  • spring学习(十七)--annotion注解

    Spring的配置一般可以完全在XML文件的<beans>空间中配置完成,但是在庞大的企业应用程序中,可能会定义数百个bean,显然这种方式是很难基于Spring源码去调试的,所以基于这个考虑出现了混合配置的概念。

    混合配置的核心是组件扫描和注解配置。通过使用组件扫描,Spring将扫描通过特定注解指定的包查找类,标注了@Component(@org.springframework.stereotype.Component)、@Controller、@Repository、@Service的类将成为Spring管理的bean,其中也可以创建自己的组件注释;注解配置的一个关键注解是:@org.springframework.beans.factoryannotation.Autowired,@Autowired声明了Spring应该在实例化之后注入的依赖。

    Warnning:组件扫描默认将扫描所有的@Component注解,要想做到分离bean,使得根应用上下文保存服务、仓库和其他业务逻辑片段,而DispatcherServlet的应用上下文只包含Web控制器,可以通过filter增加黑白名单来实现:

    applicationContext.mxl中:
     <context:component-scan base-package="com.wrox">
          <context:exclude-filter expression="org.springframework.stereotype.Controller"    type="annotation" /> 
     </context:component-scan>
     
    spring-mvc.xml中:
      <context:component-scan base-package="com.wrox"   use-default-filters="false"> 
          <context:include-filter expression="org.springframework.stereotype.Controller"    type="annotation" /> 
     </context:component-scan>
    个人理解,如有错误,欢迎指正!
  • 相关阅读:
    UML——六大关系整理
    C#编写Windows 服务
    Centos7下lamp环境搭建的小笔记
    awk命令分析日志的简单笔记
    ssrf小记
    关于cookie的一些学习笔记
    xssbypass小记
    xss挑战赛小记 0x03(xssgame)
    xss挑战赛小记 0x01(xsstest)
    ubuntu下安装LAMP环境遇到的一些小问题
  • 原文地址:https://www.cnblogs.com/gllegolas/p/11765105.html
Copyright © 2011-2022 走看看