SpringBoot 使用 xml 配置

123 阅读1分钟

SpringBoot 官方提倡零配置,不推荐使用 xml 配置,但是有的时候可能必须要使用 xml 配置,所以就可以用 @ImportResource 来帮助我们解决这个问题。

只要在 Spring Boot 启动类上,使用 @ImportResource 的 locations 即可。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@ImportResource(locations = {"classpath:demo.xml"})
@SpringBootApplication
public class SpringbootBoot02ConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootBoot02ConfigApplication.class, args);
    }
}