简体   繁体   English

Springboot将应用程序yaml文件放在resources/config/文件夹中,运行JAR时找不到资源

[英]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

Extracted JAR as well也提取了 JAR 在此处输入图像描述

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.

相关问题 如何获取springboot应用程序资源中所有扩展名为xml的文件? - How to get all files with xml extension placed in resources of springboot application? 无法在Spring引导应用程序中将src / main / resources / static / css /文件夹中的css文件提供给客户端 - Unable to serve css files placed in src/main/resources/static/css/ folder to client in Spring boot application 应用程序(src / main)运行时,类路径中的src / test / resources中的文件是? - Are files in src/test/resources on classpath while application (src/main) is running? Jar文件无法正常运行,资源无法加载 - Jar files not running correctly and resources not loading 运行 jar 时将资源文件夹路径传递给命令 - Pass Resources Folder path to the command when running a jar 在 Spring 引导应用程序中从 JAR 上的资源文件夹中获取图像 - Get images from resources folder on a JAR in a Spring boot application 如何播放 Jar 文件中资源文件夹中的 MP3 文件? - How to play MP3 files that are in the resources folder in a Jar file? 如何将jar包中的资源文件夹复制到程序文件中 - How to copy resources folder out of jar into program files 如何访问位于jar的'META-INF / resources'文件夹中的jsp页面中的Exception对象? - How to access Exception object in a jsp page placed at 'META-INF/resources' folder of jar? jar文件夹中的资源列表? - List of resources in a folder of jar file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM