首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在Spring中为类路径提供外部配置资源(数据库属性和XML文件)

如何在Spring中为类路径提供外部配置资源(数据库属性和XML文件)
EN

Stack Overflow用户
提问于 2019-06-27 02:48:00
回答 1查看 444关注 0票数 0

在春季启动时,我一直面临着将外部配置文件配置到类路径的问题,但它没有从外部配置文件夹选择application.properties,即应用程序-dev属性。它从外部配置文件夹中选择数据库属性和XML文件,我尝试了以下方法,请您帮助我解决这个问题。

/ -cp ./config/;./lib/ips--0.0.1-SNAPSHOT.jar java -cp ./config/;./lib/ips-rest-0.0.1-SNAPSHOT.jar java -jar ./lib/ips-rest-0.0.1-SNAPSHOT.jar -Spring.config.Location= classpath:/ config/,file:./config/,classpath://

代码语言:javascript
代码运行次数:0
运行
复制
@ImportResource("classpath:ips-spring.xml")
@SpringBootApplication(exclude = { KafkaAutoConfiguration.class })
@ComponentScan(value = "com.mark", useDefaultFilters = false)
@EnableAutoConfiguration
@EnableConfigurationProperties
public class ApplicationRest {
    public static void main(String[] args) {
        System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(ApplicationRest.class, args);
        System.out.println("Started ApplicationRest");
    }
}

<context:property-placeholder location="classpath:env.properties,classpath:db.properties" ignore-resource-not-found="false" ignore-unresolvable="false" />
<import resource="classpath:app-entity.xml" />
EN

回答 1

Stack Overflow用户

发布于 2019-06-27 04:17:28

我假设“外部配置”指的是未打包到spring引导工件中的配置文件(*.properties*.yml等)(在您的示例中是Jar)。

在这种情况下,根据定义,它们不在应用程序的classpath中。

因此,您需要了解如何向spring应用程序提供外部配置文件。正如您已经发现的那样,--spring.config.location确实是一条出路:

代码语言:javascript
代码运行次数:0
运行
复制
--spring.config.location=file:/work/config1.yml,file:/work/config2.yml
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56783227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档