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;


  • 相关阅读:
    数组对象
    禁止鼠标右键保存图片、文字,禁止拖动图片等代码
    解决vscode 电脑卡顿
    vscode Html标签自动补全
    git提交报错
    作为一个程序员为什么要写博客?
    aaa
    JDBC
    去ioe
    去中心化
  • 原文地址:https://www.cnblogs.com/redcoatjk/p/3562366.html
Copyright © 2011-2022 走看看