`
darrenzhu
  • 浏览: 784490 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

annotation-config vs(对比) component-scan

阅读更多
<cx:annotation-config/> 可以处理@Autowired,但是不能处理@Component, @Service, @Repository 所以如果你使用了@Component, @Service, @Repository就必须添加<cx:component-scan base-package="">.

<cx:component-scan ..>包含了<cx:annotation-config/>的功能,并且还可以处理@Component, @Service, @Repository, 所以你只要使用了<cx:component-scan ..>,
就不需要添加<cx:annotation-config/>

http://techidiocy.com/annotation-config-vs-component-scan-spring-core/

annotation-config :  Annotation config main job is to activate all the annotations that are present in java beans and those are already registered either by defining in your application context file or being registered while component scanning. Important point is they need to be registered.

component-scan : Component scan can do everything that annotation config does , in addition to it it also registers the java classes as spring bean those are annotated with @Component , @Service ,@Repository etc.
分享到:
评论

相关推荐

    spring

    关于上下文:annotation-config与上下文:component-scan context:annotation-config:作用是可以使用@ Autowired,@ Inject等来省略xml配置文件中的属性属性,简化配置; context:component-scan:作用是可以...

    Spring Context测试

    学习spring组件扫描(Component Scanning)的代码 ...&lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.test"&gt;&lt;/context:component-scan&gt; 2.在需要装配的类的上面全部加上@Component

    java8stream源码-java:java及相关(电话/微信:15850669069,qq:1056764180)

    context:annotation-config vscontext:component-scan linux部署运维 [Linux Tune Network Stack (Buffers Size) To Increase Networking Performance]) c++ 其他 [Real Time Analytics with Druid, Spark, and ...

    struts2.3+hibernate3.6+spring3.1整合的纯xml配置的小项目

    &lt;context:component-scan base-package="org.whvcse"&gt;&lt;/context:component-scan&gt; &lt;tx:annotation-driven transaction-manager="txManager" /&gt; &lt;!-- &lt;aop:config&gt; expression="execution(* x.y.service.*...

    Spring AOP配置源码

    &lt;/beans&gt;&lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.spring.*"/&gt; 两行为开启spring的注解配置 &lt;aop:aspect id="aspect" ref="logIntercepter"&gt; 引入具体的AOP操作类 (* ...

    维生药业小项目 SSH简单学习项目

    &lt;context:annotation-config/&gt; &lt;property name="driverClass" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt; ...

    SpringMVC+Hibernate全注解整合

    &lt;context:component-scan base-package="com.org.*" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;!-- 配置jdbc --&gt; &lt;bean class="org.springframework.beans.factory.config....

    spring3.2+strut2+hibernate4

    &lt;context:component-scan base-package="*" /&gt; &lt;!-- &lt;aop:config&gt;--&gt; &lt;!-- execution第一个星号代表任何返回类型,第二个星号代表com.sbz.service下的所有包,第三个星号代表所有方法,括号中的两个点代表任何...

    springmvc-ibatis

    &lt;context:annotation-config/&gt; &lt;!-- 扫描包 --&gt; &lt;context:component-scan base-package="com.org"/&gt; &lt;!-- 匹配jsp文件下面的所有.jsp的页面 --&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;!-...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    &lt;context:component-scan base-package="com.mvc" /&gt; &lt;mvc:annotation-driven /&gt; **" location="/resources/" /&gt; &lt;mvc:default-servlet-handler /&gt; &lt;aop:config proxy-target-class="true"/&gt; &lt;tx:annotation-...

    SpringMVC-SSH全注解

    &lt;context:component-scan base-package="com.org.core"/&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;!-- 配置jdbc --&gt; &lt;bean class="org.springframework.beans.factory.config....

    spring_MVC源码

    10. &lt;context:annotation-config /&gt; 11. &lt;!-- 把标记了@Controller注解的类转换为bean --&gt; 12. &lt;context:component-scan base-package="com.mvc.controller" /&gt; 13. &lt;!-- 启动Spring MVC的注解功能,...

    轻量级高性能 RPC 框架 HRPC.zip

     &lt;context:annotation-config/&gt;  &lt;context:property-placeholder location="classpath:system.properties"/&gt;  &lt;!--客户端配置--&gt;   id="rpcClient" class="com.yingjun.rpc.client.RPCClient"&gt;  ...

    spring applicationContext 配置文件

    &lt;context:component-scan base-package="com.ccc"/&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="0" /&gt; &lt;!-- 配置事务管理器 針對MES數據庫-...

    java微信公众号MVC开发框架

    component-scan配置了微信接口服务类,里面包含常用的微信公众号接口服务,例如菜单管理、消息服务、二维码服务、用户管理、微信网页授权、素材管理等服务内容,在web应用控制器类和微信控制器类里面可以通过@...

    springmybatis

    DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt; &lt;typeAliases&gt; &lt;typeAlias alias="User" type="com.yihaomen.mybatis.model.User"/&gt; ...

    客户关系管理系统框架搭建(二)

    &lt;context:component-scan base-package="cn.itcast.crm"/&gt; &lt;!--3 配置本地化代理工程bean,这是spring整合hibernate的入口 --&gt; &lt;!--表示在类路径下加载hibernate.cfg.xml --&gt; ...

Global site tag (gtag.js) - Google Analytics