Spring Boot @ImportResource注释示例
Spring提供了一个 @ImportResource 注释,用于将applicationContext.xml文件中的bean加载到Application Context中。
@ImportResource({ “ classpath *:applicationContext.xml ” })
在Spring Boot的入口类中我们使用:
@SpringBootApplication
@EnableSwagger2
@ImportResource({"classpath*:applicationContext.xml"})
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
}
推荐的方法是创建一个单独的配置类来加载此XML bean定义文件。
@Configuration
@ImportResource({"classpath*:applicationContext.xml"})
public class XmlConfiguration {
}