`
darrenzhu
  • 浏览: 797480 次
  • 性别: 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.
分享到:
评论

相关推荐

    异常解决:错误:namespace element 'annotation-config' … on JDK 1.5 and higher

    2. **XML配置问题**:确保你的Spring配置文件(如`applicationContext.xml`)正确包含了`&lt;context:component-scan&gt;`或`&lt;context:annotation-config&gt;`元素,它们是启用注解配置的关键。 3. **编译器设置**:检查你的...

    详解Spring框架注解扫描开启之配置细节

    自动装配实现需要注解扫描,这时发现了两种开启注解扫描的方式,即 `&lt;context:annotation-config/&gt;` 和 `&lt;context:component-scan&gt;`。 `&lt;context:annotation-config/&gt;` `&lt;context:annotation-config/&gt;` 用于开启...

    spring

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

    15、spring 配置以及使用 1

    在这个主题中,我们将深入探讨`&lt;context:annotation-config&gt;`与`&lt;context:component-scan&gt;`的区别,事务管理器的配置,以及Spring开发环境的选择和数据源的配置。 1. `&lt;context:annotation-config&gt;`和`&lt;context:...

    Spring的Annotation配置相关讲义

    `&lt;context:component-scan&gt;`元素用于指定需要扫描的包,这样Spring会自动发现这些包下标记了如`@Component`、`@Service`、`@Repository`等注解的类,并将它们注册为Bean。 接着,我们看DAO层的配置。使用`@...

    Spring注解详解

    &lt;context:annotation-config /&gt; ``` 这将隐式地向 Spring 容器注册 `AutowiredAnnotationBeanPostProcessor`、`CommonAnnotationBeanPostProcessor`、`PersistenceAnnotationBeanPostProcessor` 和 `...

    使用Spring2.5的Autowired实现注释型的IOC

    在上面的配置文件中,我们使用了 `&lt;context:annotation-config/&gt;` 和 `&lt;context:component-scan base-package="testspring.main"/&gt;` 两个标签。 `&lt;context:annotation-config/&gt;` 用于启用注释型的 IOC,而 `...

    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

    spring注解使用

    在上面的配置文件中,我们使用了 `&lt;context:annotation-config/&gt;` 和 `&lt;context:component-scan&gt;` 两个元素。`&lt;context:annotation-config/&gt;` 元素用于激活注解驱动的 Bean, `&lt;context:component-scan&gt;` 元素用于...

    spring注解

    &lt;context:annotation-config /&gt; ``` 这将隐式地向 Spring 容器注册 `AutowiredAnnotationBeanPostProcessor`、`CommonAnnotationBeanPostProcessor`、`PersistenceAnnotationBeanPostProcessor` 和 `...

    spring包扫描配置的项目

    在Spring中,包扫描是通过`&lt;context:component-scan&gt;`标签实现的,该标签位于XML配置文件中。这个标签告诉Spring去指定的包及其子包下查找标记为`@Component`、`@Service`、`@Repository`和`@Controller`的类,这些...

    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.*...

    JSP 中spring事务配置详解.docx

    在这个配置中,`&lt;context:component-scan&gt;`用于自动扫描指定包下的类,发现`@Repository`、`@Service`等注解并进行注册。`&lt;context:annotation-config&gt;`启用对注解的处理,使得我们可以使用`@Transactional`注解来...

    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操作类 (* ...

    spring 定时器

    - **`&lt;context:component-scan&gt;`**: 指定扫描的包路径,用于发现带`@Scheduled`注解的类。 #### 四、`@Scheduled`注解的使用 `@Scheduled`是Spring提供的一种用于定义定时任务的注解,其主要属性包括: - **`cron...

    spring mvc

    2. `&lt;context:component-scan&gt;`: - 这个元素告诉Spring扫描指定包及其子包,寻找带有`@Controller`注解的类,并将它们作为bean进行管理。 3. `&lt;mvc:annotation-driven&gt;`(通常也会包含,但此处未提供): - 这个...

    Spring3注解介绍.docx

    3. **组件扫描**:通过`&lt;context:component-scan&gt;`元素,不仅注册注解处理器,还可以扫描指定包下的类,自动发现和处理注解: ```xml &lt;context:component-scan base-package="com.yourpackage"/&gt; ``` `base-...

Global site tag (gtag.js) - Google Analytics