首页 > 其他分享 >8.容器功能-ImportResource-原生配置文件引入

8.容器功能-ImportResource-原生配置文件引入

时间:2022-09-03 03:33:25浏览次数:44  
标签:原生 ImportResource springboot 配置文件 xml haha hehe

在xml配置文件中配置的bean 在springboot中是无法正常使用的,因为用的不是这个方法了

ApplicationContext ctx= new ClassPathXmlApplicationContext("bean.xml");

在springboot中用的
SpringApplication.run(App.class, args);

 

要中springboot中使用原来的xml配置的bean 就需要使用@ImportResource 

@ImportResource("classpath:beans.xml") //
public class MyConfig {}

======================测试=================
        boolean haha = run.containsBean("haha");
        boolean hehe = run.containsBean("hehe");
        System.out.println("haha:"+haha);//true
        System.out.println("hehe:"+hehe);//true

 

@ImportResource("classpath:beans.xml") 中配置类上 加上这个注解 指定spring的xml 就自动加入容器了

标签:原生,ImportResource,springboot,配置文件,xml,haha,hehe
From: https://www.cnblogs.com/dzs894330350/p/16651856.html

相关文章