zoukankan      html  css  js  c++  java
  • [转]spring学习笔记:annotation的使用3

    摘自wjt276的笔记
    ---------------------  

    一、        @Scope@PostConstruct@PreDestroy

    @Scope对应于xml配置文件的scope属性

    @PostConstruct对应于xml配置文件中的init-method属性

    @PreDestroy对于应于xml配置文件中的destroy-method属性

    例如如下:

    import javax.annotation.PostConstruct;

    import javax.annotation.PreDestroy;

    import javax.annotation.Resource;

    import org.springframework.context.annotation.Scope;

    import org.springframework.stereotype.Component;

    @Component(value="userService")

    @Scope("singleton")

    public class UserService {

        @PostConstruct

        public void init(){System.out.println("现在开始初始化UserService");}

        private UserDao userDao = new UserDaoImpl();

        public UserDao getUserDao() {return userDao;}

        @Resource

        public void setUserDao(UserDao userDao) {this.userDao = userDao;}

        public void add(User u){ userDao.save(u);}

        @PreDestroy

        public void destroy(){System.out.println("destory"); }

     

     

    二、        注解对应的jar

    1@Autowired           org.springframework.beans.factory.annotation.Autowired;

    2@Qualifier             org.springframework.beans.factory.annotation.Qualifier;

    3@Componet           org.springframework.stereotype.Component;

    4@Resource             javax.annotation.Resource;

    5@Scope                  org.springframework.context.annotation.Scope;

    6@PostConstruct     javax.annotation.PreDestroy;

    7@PreDestroy          javax.annotation.PreDestroy;


  • 相关阅读:
    iOS开发系列-Category
    OC开发系列-内存管理
    OC开发系列-@property和@synthesize
    OC开发系列-成员变量的作用域
    OC开发系列-类与对象
    MySQL
    JavaWeb
    POJ1845-Sumdiv大数约数和
    poj1159 Palindrome 区间DP
    poj 2955 Brackets 区间DP
  • 原文地址:https://www.cnblogs.com/redcoatjk/p/3562366.html
Copyright © 2011-2022 走看看