[英]Application.properties not detected by spring boot 2.5.3
我已将我的项目从 gradle 5 迁移到 7.1 和 spring boot 2.5.3。 在构建 jar 之后,我尝试执行相同的操作。 早些时候它工作正常。 但是现在,它没有检测到 application.properties 文件。 我在 Stackoverflow 和其他网站上尝试了很多解决方案,但对我没有帮助。 如果有人能指出我的错误,那将非常有帮助。 我正在尝试在 windows 机器上执行。 application.properties 文件存在于与 jar 平行的配置文件夹中
尝试 1 :
java -Dloader.path=.,config\ -jar xyz-1.0.0.jar
错误:
class path resource [application.properties] cannot be opened because it does not exist
尝试 2 :
java -Dspring.config.location=classpath:/application.properties -jar xyz-1.0.0.jar
错误:
ConfigDataResourceNotFoundException: Config data resource 'class path resource [application.properties]' via location 'classpath:/application.properties' cannot be found
尝试 3 :
java -jar xyz-1.0.0.jar -Dspring.config.location=classpath:/application.properties
错误:
FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
尝试 4 :
java -Dspring.config.location=file:c:\Sheljith\tools\config\application.properties -jar xyz-1.0.0.jar
错误:
FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
尝试 5 :
java --spring.config.location=file:c:\Sheljith\tools\config\application.properties -jar xyz-1.0.0.jar
错误:
Unrecognized option: --spring.config.location=file:c:\Sheljith\tools\config\application.properties
尝试 6 :
java -Dspring.config.name=application -Dspring.config.location=file:///C:/Sheljith/tools/drc-reports-generator/config/ -jar xyz-1.0.0.jar
错误:
.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
尝试 7 :
java -Dspring.config.location=file:///C:/Sheljith/tools/config/application.properties -jar xyz-1.0.0.jar
错误:
class path resource [application.properties] cannot be opened because it does not exist
build.gradle
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin")
}
}
plugins {
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
jar.archiveName = "drc-reports-generator.jar"
version = '1.0.0'
sourceCompatibility = '1.8'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version
}
}
repositories {
mavenCentral()
mavenLocal()
}
processResources{
exclude '*/**'
}
springBoot{
mainClass = "com.xyz.Application"
}
dependencies {
implementation group: 'commons-collections', name: 'commons-collections', version: '3.2'
implementation("org.springframework.boot:spring-boot-starter")
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
testImplementation group: 'junit', name: 'junit', version: '4.+'
testImplementation group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.13.1'
implementation 'com.itextpdf:itextpdf:5.5.11'
implementation 'org.springframework:spring-web:4.3.6.RELEASE'
implementation 'com.microsoft.sqlserver:sqljdbc4:4.0'
implementation("com.h2database:h2")
implementation("org.apache.commons:commons-lang3:3.0")
implementation group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '3.0.0'
}
test {
useJUnitPlatform()
}
由于 application.properties 文件位于与 jar 文件并行的位置。 尝试这个:
java -jar xyz-1.0.0.jar --spring.config.location=application.properties
编辑:你能试试这个吗:
java -Dspring.config.additional-location=application.properties -jar xyz-1.0.0.jar
将现有的 processResources 更改为以下内容: // 排除 jar 中的所有资源
jar {
processResources.exclude('*')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.