java - 如何使用Spring-Boot导入appContext.xml?

标签 java spring spring-boot

我有一个基于注释的 spring-boot 应用程序,想要导入 src/main/webapp/WEB-INF/appContext.xml

以下方法不起作用:

@Configuration
@EnableAutoConfiguration
@ImportResource("classpath*:appContext.xml")
public class AppConfig {

}

但是如果我将 appContext.xml 复制到 src/main/resources ,它就会按预期工作。

如何使 WEB-INF 文件夹正常工作?

最佳答案

好的,根据 @geoand 发布的文档,我发现了以下内容:

Do not use the src/main/webapp folder if your application will be packaged as a jar. Although this folder is a common standard, it will only work with war packaging and it will be silently ignored by most build tools if you generate a jar.

很明显,我确实应该将上下文文件复制到 src/main/resources

关于java - 如何使用Spring-Boot导入appContext.xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622906/

相关文章:

java - Java 中的 while 循环同时返回祝贺和抱歉消息

java - 遗留代码的集成测试中如何处理事务

spring-boot - 使用 Eureka 客户端和自定义上下文路径的 Spring Boot 管理在健康状态上失败

java - Spring Security Java 配置未注册 ContextLoaderListener

java - ARCORE:点击后不显示 View (信息卡)

java - 用户定义的包和系统定义的java包在访问静态内容方面有什么区别

java - Spring @Autowire 的行为方式很奇怪,为初始化的 bean 返回 null

java - 将 JSON 文本文档与 Spring Data MongoDB 结合使用的目的是什么?

Spring rest api 相同的 url 用于批量和单个请求

java - 如何参数化 Spring Controller 和 thymeleaf 中的链接值?