gpt4 book ai didi

java - BuildProperties Spring Boot 2.1.5 和 eclipse 的 Autowiring 失败

转载 作者:行者123 更新时间:2023-12-01 09:30:55 24 4
gpt4 key购买 nike

我正在使用一些 REST API 创建一个非常简单的应用程序,并且在我尝试在我的健康检查 API 上使用 BuildProperties 之前,它目前可以正常工作。在启动我的应用程序时,我收到以下错误:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-17 09:54:29.210 ERROR 10796 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field buildProperties in com.controller.HealthCheck required a bean of type 'org.springframework.boot.info.BuildProperties' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
- Bean method 'buildProperties' in 'ProjectInfoAutoConfiguration' not loaded because @ConditionalOnResource did not find resource '${spring.info.build.location:classpath:META-INF/build-info.properties}'


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.boot.info.BuildProperties' in your configuration.

我去了构建文件,我还查看了构建创建的 jar 文件,我看到 build-info.properties 实际上在那里。在 jar 文件中,文件路径为“BOOT-INF\classes\META-INF\”。我还有其他没有问题的“自动连线”元素。

我的代码失败的地方:
@RestController
public class HealthCheck {

@Autowired
Environment environment;

@Autowired
BuildProperties buildProperties;


@GetMapping("/health")
public HealthCheckResponse healthCheck() {
return getHealthCheckResponse();
}

private HealthCheckResponse getHealthCheckResponse(){
HealthCheckResponse healthResponse = new HealthCheckResponse();
String[] profiles = environment.getActiveProfiles();

healthResponse.setServerTime(new Date());
healthResponse.setVersion(buildProperties.getVersion());
healthResponse.setEnvironment(profiles[0]);

return healthResponse;
}

我的gradle构建文件:
plugins {
id 'org.asciidoctor.convert' version '1.5.3'
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'eclipse'
apply plugin: 'java'

group = 'com'
version = '0.0.1'
sourceCompatibility = '12'

repositories {
mavenCentral()
}

ext {
set('snippetsDir', file("build/generated-snippets"))
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:2.1.1'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-webtestclient'
testImplementation 'org.springframework.security:spring-security-test'
}

test {
outputs.dir snippetsDir
}

asciidoctor {
inputs.dir snippetsDir
dependsOn test
}

springBoot {
buildInfo()
}

构建信息.properties:
#Properties
#Mon Jun 17 10:52:04 EDT 2019
build.version=0.0.1
build.group=com
build.name=app
build.artifact=app
build.time=2019-06-17T14\:52\:04.829909200Z

最佳答案

在 pom.xml 末尾添加/修改:

<build>
<finalName>{NAME_YOUR_PROJECT}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

关于java - BuildProperties Spring Boot 2.1.5 和 eclipse 的 Autowiring 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56634081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com