springboot开发,常用注解的方式,进行自动装配。
但是有时为了同时兼容项目中原来的bean xml配置,那么应该如何把xml文件 加载到 ioc容器中呢,比如 在resources 目录下,有个 springContext.xml 的xml配置文件,我们只需要 加一个注解搞定:
@ImportResource(locations = "springContext.xml")
代码如下:
@Configuration
@ImportResource(locations = "springContext.xml")
public class MyConfig {
}