Spring 注解配置

2017-12-19  本文已影响0人  Mr_ZZ先生

1.也是配置Spring 的核心包 4 +2 

4+2

2.在applicationContext.xml 文件 配置扫描注解语句

配置扫描注解

3.举例 这就相当于将 类User 注册到Spring 容器中为user 其中@Component 可以根据对应的不同层  可以写为  @Service("user")  @Controller("user")  @Repository("user")  其实底层都一样  为了方便开发者

注解

4.注解属性:

(1)@Scope(scopeName = "singleton" | "prototype") 单例 / 多例

(2) 2种

      @Value("tom")

      private String name;

      @Value("30")

      public void setAge(Integer age) {

      this.age = age;

      }

3.当属性为引用数据类型的时候

(1)先将引用类注入到Spring中  (2)autoWried(自动装载) @Qualifier("car2")指定装载的具体类

上一篇 下一篇

猜你喜欢

热点阅读