java - 无法在 macos 上运行 spring boot 项目
问题描述
我有一个项目spring boot java。我可以在 Windows、kali 和 ubuntu 上部署一切。但是对于macos,我遇到了这样的问题。帮我解决这个问题,好吗?
java -jar xxx.jar
11:16:02.681 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Unable to load config data resource from pattern 'file:./config/*/application.properties'
at org.springframework.boot.context.config.LocationResourceLoader.getDirectory(LocationResourceLoader.java:141)
at org.springframework.boot.context.config.LocationResourceLoader.getResources(LocationResourceLoader.java:102)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolvePattern(StandardConfigDataLocationResolver.java:259)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:245)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:219)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:111)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$1(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:125)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:106)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:101)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:93)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:81)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:118)
at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:230)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:217)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:88)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:80)
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:203)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:196)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:170)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:148)
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:1507)
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 org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.example.demo.WebToolsApplication.main(WebToolsApplication.java:10)
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:567)
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)
**Caused by: java.lang.IllegalStateException: 'config' is not a directory**
at org.springframework.util.Assert.state(Assert.java:97)
at org.springframework.boot.context.config.LocationResourceLoader.getDirectory(LocationResourceLoader.java:137)
... 42 common frames omitted
解决方案
您已将 application.properties 文件外部化。有多种方法可以解决这个问题,我在下面写下其中两个:---
第一种解决方法:--
创建一个配置文件夹,在其中放置 jar 文件 n 将 application.properties 放入配置文件夹中。
Ex-
if your jar is inside /home/user folder
then your property file should be inside /home/user/config/application.properties
然后运行:
java -jar <yourjar>
第二种解决方法:--
给出正确的路径位置:--
java -jar <yourjar> --spring.config.location=<property file path>
推荐阅读
- android - 重命名包名称后 Firebase API 初始化失败
- laravel - Laravel 模型控制器依赖注入
- sql - 列出特定查询的至少有一行具有非空值的表的列
- javascript - 在 node.js 中为链式函数编写笑话测试
- android - 在后台服务中拦截 Android 蓝牙相机快门
- python - Python:如何在 kivy 中使标签加粗
- javascript - 将当前日期与从 api 响应收到的日期进行比较
- powershell - Powershell cmdlet New-AzureRmSqlDatabaseExport 中的共享访问签名 (SAS) 密钥有什么格式?
- php - 数组到对象抛出未捕获的错误:调用未定义的方法 stdClass
- excel - 将 16 名玩家分成 4 组,其中没有人来自同一个较早的组