Some initialization after the start of the project method

 

@PostConstruct method annotated comments

 

@Compant
 public  class InitDemo { 

    @PostConstruct 
    public  void the init () {
         // item will start performing the method 
        doSomething (); 
    } 
}

xml configured in the following manner

 

<bean id="InitDemo" class="com.xxx.InitDemo" scope="singleton" init-method="init"> </bean>

 

Or implemented InitiallizingBean, in the process arterPropertiesSet

@Component
public class InitDemo implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {

       //doSomeThing
    }
 
参考:https://blog.csdn.net/u010742049/article/details/82686059 

 

Execution order. Constructor> @PostConstruct> InitiallizingBean> init-method

Guess you like

Origin www.cnblogs.com/changeCode/p/10980725.html
Recommended