Spring Ioc Configration - Annotation

1.配置类注解@Configuration.

2.Bean注解 @Bean.

3.导入其他配置类@Import.

4.回调函数

@Bean(initMethod = "init", destroyMethod = "cleanup" )

5.作用范围

   @Scope("prototype") 

6.例子

Spring Ioc Configration - Annotation
public static void main(String[] args) {
   AnnotationConfigApplicationContext ctx = 
   new AnnotationConfigApplicationContext();

   ctx.register(AppConfig.class, OtherConfig.class);
   ctx.register(AdditionalConfig.class);
   ctx.refresh();

   MyService myService = ctx.getBean(MyService.class);
   myService.doStuff();
}
Spring Ioc Configration - Annotation

或者通过注解引入

 @ContextConfiguration(classes = {PersistenceConfig.class, CoreConfig.class}) 

 

 

refer to: http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm

Spring Ioc Configration - Annotation,布布扣,bubuko.com

Spring Ioc Configration - Annotation

上一篇:Python *与** 参数问题


下一篇:JavaScript 中的一些坑(一)http://roshanca.com/traps-in-javascript-part-I/