1.配置类注解@Configuration.
2.Bean注解 @Bean.
3.导入其他配置类@Import.
4.回调函数
@Bean(initMethod = "init", destroyMethod = "cleanup" )
5.作用范围
@Scope("prototype")
6.例子
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(); }
或者通过注解引入
@ContextConfiguration(classes = {PersistenceConfig.class, CoreConfig.class})
refer to: http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm