码迷,mamicode.com
首页 > 编程语言 > 详细

用javaConfig 代替 xml 配置

时间:2017-02-28 21:43:20      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:[]   scheduler   ann   conf   rgs   java   color   pre   void   

@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 {

}

 

用javaConfig 代替 xml 配置

标签:[]   scheduler   ann   conf   rgs   java   color   pre   void   

原文地址:http://www.cnblogs.com/diaoniwa/p/6480822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!