zoukankan      html  css  js  c++  java
  • spring的@PostConstruct 和 @PreDestory注解,类似于在配置文件中定义init-method 和 destory-method方法

    import javax.annotation.PostConstruct;  
    import javax.annotation.PreDestroy;  
      
    public class PersonService {  
        
        private String  message;  
      
        public String getMessage() {  
            return message;  
        }  
      
        public void setMessage(String message) {  
            this.message = message;  
        }  
          
        @PostConstruct  
        public void  init(){  
            System.out.println("I'm  init  method  using  @PostConstrut...."+message);  
        }  
          
        @PreDestroy  
        public void  dostory(){  
            System.out.println("I'm  destory method  using  @PreDestroy....."+message);  
        }  
          
    }  

    然后,在spring.xml中配置bean,最后启动:

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    PersonService personService = (PersonService)context.getBean("personService");
    context.destroy();
    这个博客主要是javaEE相关或者不相关的记录, hadoop与spark的相关文章我写在下面地址的博客啦~ http://www.cnblogs.com/sorco
  • 相关阅读:
    0455分发饼干 Marathon
    0078子集 Marathon
    python 实现JWT Marathon
    0376摆动序列 Marathon
    0216.组合总和 III Marathon
    028实现strStr() Marathon
    0738单调递增的数字 Marathon
    0051N皇后 Marathon
    0047全排列II Marathon
    0037解数独 Marathon
  • 原文地址:https://www.cnblogs.com/orco/p/6595530.html
Copyright © 2011-2022 走看看