用javaConfig 代替 xml 配置

@Configuration //注册该类作为javaconfig
public class ApplicationConfig {
    @Bean(name = "helloBean")  //注册该对象为bean
    public Helloworld helloworld(){
        return new HelloworldImpl();
    }
}

Application

public class Application {
    public static void main(String[] args){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig.class);
        Helloworld helloworld = (Helloworld) applicationContext.getBean("helloBean");
        helloworld.printHelloWorld("This is Spring_JavaConfg!hhhh");
    }
}

2.用@Import加载多个配置文件

@Configuration
@Import({ CustomerConfig.class, SchedulerConfig.class })
public class AppConfig {

}

 

posted @ 2017-02-28 20:41  写代码隔扣邓肯  阅读(358)  评论(0编辑  收藏  举报