how to set default beans init-method by annotations in spring 4?

how to set default beans init-method by annotations in spring 4?

配置文件实现的



    
    

    
    


You could do the following:

@Configuration
public class SomeConfig {

   @Bean(initMethod = "initMethodName")
   public SomeBeanClass someBeanClass() {
      return new SomeBeanClass();
   }
}

You would repeat that for every bean you want to call initMethodName on.

You could take it one step further and implement a meta-annotation like

@Bean(initMethod = "initMethodNAme")
public @interface MyBean {
}

and simply use @MyBean instead of @Bean(initMethod = "initMethodName") in SomeConfig

你可能感兴趣的:(how to set default beans init-method by annotations in spring 4?)