節錄重點:

@ Resource 、@ PostConstruct、@ PreDestro、@PersistenceContext、@Required 都必須聲明相關的 bean

所以如果總是需要按照傳統的方式一條一條配置顯得有些繁瑣和沒有必要,於是spring給我們提供<context:annotation-config/>的簡化配置方式,自動幫你完成聲明。

但使用註解一般都會配置掃瞄包路徑選項

<context:component-scan base-package=」XX.XX」/>

該配置項其實也包含了自動注入上述processor的功能,因此當使用 <context:component-scan/> 後,就可以將 <context:annotation-config/> 移除了。

原文出處:

http://mushiqianmeng.blog.51cto.com/3970029/723880

英文:

How to use

http://howtodoinjava.com/spring/spring-core/how-to-use-spring-component-repository-service-and-controller-annotations/

Difference Between @Component, @Service, @Repository and @Controller:

http://javapapers.com/spring/spring-component-service-repository-controller-difference/

[ Java ] [ Spring ] Spring 一些配置项 及 <context:annotation-config/> 專文解释说明的更多相关文章

  1. 【Java】Spring之基于注释的容器配置(四)

    注释是否比配置Spring的XML更好? 基于注释的配置的引入引发了这种方法是否比XML“更好”的问题.答案是每种方法都有其优点和缺点,通常,由开发人员决定哪种策略更适合他们.由于它们的定义方式,注释 ...

  2. spring 2.5.6 错误:Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher

    在运行一个第三方公司交付的项目的时候, 出现: Caused by: java.lang.IllegalStateException: Context namespace element 'annot ...

  3. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL,spring获取context

    今天学习spring项目的时候出现了下面的错误信息: java.lang.ClassNotFoundException: org.springframework.web.context.Context ...

  4. Spring配置之context:annotation与、component-scan以及annotation-driven

    spring boot帮助我们隐藏了大量的细节,有些配置spring boot都是开启的,因此当我们查看遗留项目使用spring时候遇见问题一定细心排查 <!-- context:annotat ...

  5. maven创建spring项目之后,启动报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    出错情景:maven中已经加载了spring的核心包,但是项目启动时,报错: org.apache.catalina.core.StandardContext listenerStart严重: Err ...

  6. spring异常 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderServlet

    spring异常 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderServlet   情况 ...

  7. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener,环境Spring+Maven

    记录一下莫名出现的错误.Spring+Maven+STS. 严重: Error configuring application listener of class org.springframewor ...

  8. maven创建spring项目之后,启动报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade

    错误: org.apache.catalina.core.StandardContext listenerStart严重: Error configuring application listener ...

  9. 在eclipse中运行spring web application时的异常: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

随机推荐

  1. css hover图片hover效果兼容ie8

    例子: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  2. js控制分页打印、打印分页示例

    1 打印分页 需要添加一段代码 <div  style="page-break-before:always;"><br /></div> 2 & ...

  3. Android chromium 1

    For Developers‎ > ‎Design Documents‎ > ‎ Java Resources on Android Overview Chrome for Android ...

  4. Database Exception – yii\db\Exception

    在使用Yii2框架时遇到数据库无法访问的问题: 这个是由于 通常我们在参考 教程在 MAC OS LINUX下安装 MYSQL 时,默认将PHP.ini 中的以下三项留空导致的Yii2所需的PDO组建 ...

  5. unity C# 获取有关文件、文件夹和驱动器的信息

    class FileSysInfo { static void Main() { // You can also use System.Environment.GetLogicalDrives to ...

  6. hihoCoder #1127 : 二分图二·二分图最小点覆盖和最大独立集

    #1127 : 二分图二·二分图最小点覆盖和最大独立集 Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB 描述 在上次安排完相亲 ...

  7. CCNP路由实验之九 路由策略

     CCNP路由实验之九 路由策略 路由器在公布与接收路由信息时,可能须要实施一些策略.以便对路由信息进行过滤,比如仅仅接收或公布满足一定条件的路由信息. 一种路由协议可能须要引入其它的路由协议发现 ...

  8. iOS App 上架流程

                                                             iPhone App 上架流程 1.  申请 App ID (1)  连到 Devel ...

  9. 对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了

    对照 Android 的 Intent 与 iOS StoryBoard 的 Segue - Intent 假设也能添加个prepareForSegue回调就好了 太阳火神的漂亮人生 (http:// ...

  10. Java中AtomicInteger的使用!!!

    今天在看Volley的源码的时候,看到里面使用了AtomicInteger这个类,曾经没用过,今天看了一下API学习了一下: 首先介绍一下这个类的用处,这个类主要是用来替换java中的自增和自减操作, ...