[英]Springboot placed application yaml files in resources/config/ folder, while running the JAR it is not able to find the resources
My Project Structure我的项目结构
AssemblyProject
|-src/main/java
|-src/main/resources
|-config
|-application-prod.yml
|-application.yml
|-application-stage.yml
|-build.gradle
I am able to generate JAR file.我能够生成 JAR 文件。 and trying to execute below command from the JAR file location并尝试从 JAR 文件位置执行以下命令
java -jar assembly-services-1.0.0.jar --spring.config.location=classpath:config/ --spring.profiles.active=stage
I am getting below Error我低于错误
14:43:15.924 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.active' imported from location 'class path resource [config/application-stage.yaml]' is invalid in a profile specific resource [origin: class path resource [config/application-stage.yaml] from assembly-services-1.0.0.jar - 38:13]
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwOrWarn$1(InvalidConfigDataPropertyException.java:124)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.throwOrWarn(InvalidConfigDataPropertyException.java:121)
at org.springframework.boot.context.config.ConfigDataEnvironment.checkForInvalidProperties(ConfigDataEnvironment.java:354)
at org.springframework.boot.context.config.ConfigDataEnvironment.applyToEnvironment(ConfigDataEnvironment.java:323)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:236)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:97)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at com.assembly.Application.main(Application.java:73)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Note : I know this is repeated question, But I have literally gone through all past stackoverflow questions related to this topc, but sadly no luck !注意:我知道这是一个重复的问题,但我确实已经完成了所有与此主题相关的 stackoverflow 问题,但遗憾的是没有运气!
The problem I can see is you must have provided active profile in your application-stage.properties
as well.我可以看到的问题是您必须在application-stage.properties
中也提供了活动配置文件。 You need to remove it.您需要将其删除。 According to spring boot documentation:根据 spring 引导文档:
So in Spring Boot 2.4 we're planning to make two significant changes to the way the properties and YAML files are loaded:因此,在 Spring Boot 2.4 中,我们计划对属性和 YAML 文件的加载方式进行两项重大更改:
Documents will be loaded in the order that they're defined.文档将按照定义的顺序加载。
Profiles can no longer be activated from profile specific documents.不能再从配置文件特定文档激活配置文件。
If you still want to use legacy configuration you need to provide spring.config.use-legacy-processing=true
to your application.properties
如果您仍想使用旧配置,则需要为您的application.properties
提供spring.config.use-legacy-processing=true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.