有关网站设计的文章,wordpress手机客户端源码,wordpress默认登录页修改,咸阳公司网站建设转载自 Spring 基于注解的配置
基于注解的配置
从 Spring 2.5 开始就可以使用注解来配置依赖注入。而不是采用 XML 来描述一个 bean 连线#xff0c;你可以使用相关类#xff0c;方法或字段声明的注解#xff0c;将 bean 配置移动到组件类本身。
在 XML 注入之前进行注解…转载自 Spring 基于注解的配置
基于注解的配置
从 Spring 2.5 开始就可以使用注解来配置依赖注入。而不是采用 XML 来描述一个 bean 连线你可以使用相关类方法或字段声明的注解将 bean 配置移动到组件类本身。
在 XML 注入之前进行注解注入因此后者的配置将通过两种方式的属性连线被前者重写。
注解连线在默认情况下在 Spring 容器中不打开。因此在可以使用基于注解的连线之前我们将需要在我们的 Spring 配置文件中启用它。所以如果你想在 Spring 应用程序中使用的任何注解可以考虑到下面的配置文件。
?xml version1.0 encodingUTF-8?beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdcontext:annotation-config/!-- bean definitions go here --/beans
一旦 被配置后你就可以开始注解你的代码表明 Spring 应该自动连接值到属性方法和构造函数。让我们来看看几个重要的注解并且了解它们是如何工作的
序号注解 描述1Required Required 注解应用于 bean 属性的 setter 方法。 2Autowired Autowired 注解可以应用到 bean 属性的 setter 方法非 setter 方法构造函数和属性。 3Qualifier 通过指定确切的将被连线的 beanAutowired 和 Qualifier 注解可以用来删除混乱。 4JSR-250 Annotations Spring 支持 JSR-250 的基础的注解其中包括了 ResourcePostConstruct 和 PreDestroy 注解。