使用 -classpath 运行时未检测到 Spring application.yml [英] Spring application.yml not detected when running with -classpath

查看:37
本文介绍了使用 -classpath 运行时未检测到 Spring application.yml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用 Spring Framework(特别是 Spring Boot),所以如果有明显的解决方案,请原谅我...

I'm using the Spring Framework (specifically Spring Boot) for the first time, so forgive me if there is an obvious solution to this...

在我的应用程序中,我有一个嵌入式 application.yml,它为整个配置参数负载提供默认值.如果我使用以下命令运行 JAR,这会正常工作:

In my application, I have an embedded application.yml which provides defaults to a whole load of configuration parameters. This works fine if I run the JAR using:

java -jar myapp.jar

但是,我的应用程序已开发用于检测类路径上的其他组件,这意味着我需要运行以下命令:

However, my application has been developed to detect additional components on the classpath, meaning I need to run the following command instead:

java -classpath .;myapp.jar;extra/* org.springframework.boot.loader.JarLauncher

像这样运行时,没有检测到嵌入的 application.yml,因此我的配置参数没有给出默认值.

When running it like this, the embedded application.yml isn't detected and therefore my configuration parameters aren't given default values.

谁能解释一下是什么原因造成的,我该如何解决这个问题?

Can anyone explain what is causing this, and how I can get around the issue?

推荐答案

我不确定我完全明白为什么,但如果其他人遇到这个问题,我发现以下工作正常(注意缺少 . 在类路径中):

I'm not sure I entirely understand why, but in case anyone else hits this issue I found the following works fine (note the lack of a . in the classpath):

java -classpath myapp.jar;extra/* org.springframework.boot.loader.JarLauncher

这篇关于使用 -classpath 运行时未检测到 Spring application.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆