在春季启动时,我一直面临着将外部配置文件配置到类路径的问题,但它没有从外部配置文件夹选择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://
@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" />
发布于 2019-06-26 20:17:28
我假设“外部配置”指的是未打包到spring引导工件中的配置文件(*.properties
、*.yml
等)(在您的示例中是Jar)。
在这种情况下,根据定义,它们不在应用程序的classpath
中。
因此,您需要了解如何向spring应用程序提供外部配置文件。正如您已经发现的那样,--spring.config.location
确实是一条出路:
--spring.config.location=file:/work/config1.yml,file:/work/config2.yml
https://stackoverflow.com/questions/56783227
复制相似问题