通过spring boot 启动类,直接运行报错
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
MyBean bean = context.getBean(MyBean.class);
System.out.println(bean);
}
}
在启动类上@ImportResource注解,指定需要加载的xml文件,
@ImportResource(locations = {"classpath:applicationContext.xml"})
此时再运行,就能正常运行了
MyBean
@Getter
@Setter
@ToString
public class MyBean {
private int id;
private String name;
}