• @ImportResouce注解加载XML配置文件

  • 编写application-bean.xml注入bean;

  • src/main/resouces下编写配置文件application-bean.xml文件


import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.ImportResource;

/**
 * classpath路径:locations={"classpath:application-bean1.xml","classpath:application-bean2.xml"}
 * file路径: locations = {"file:d:/test/application-bean1.xml"};
 */

@Configuration
@ImportResource(locations={"classpath:application-bean.xml"})
//@ImportResource(locations={"file:d:/test/application-bean1.xml"})
public class ConfigClass {

}