我正在Kubernetes 1.24上开发/运行一个SpringBoot应用程序,我也在使用它来学习几种技术,主要是使用WebClient和我的最新尝试,还使用JavaMailSender等发送电子邮件。
最近我更新了代码中的几个部分,我不再确定是什么导致了主题中的问题。
但我怀疑这可能与为我的EmailSender类添加新的@Component有关,或者我必须使用@ComponentScan来访问邮件包,因为它在我的控制器类包之外。
例如:
[...]
@Configuration
public class EmailConfiguration {
@Bean
public JavaMailSender getJavaMailSender() {
[...]
}
}
以及:
@Component
public class EmailSender {
@Autowired
private JavaMailSender emailSender;
@Bean
public void sendSimpleMessage(String to, String subject, String text) {
[...]
}
}
另外,我已经从Eclipse Temurin 17.0.6+10更新到17.0.7+7
为了获得更多的细节,我在www.example.com上添加了以下application.properties:
management.server.port=8081
management.server.address=0.0.0.0
management.endpoints.web.exposure.include=health,info,metrics,prometheus
management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.base-path=/actuator
所以我得到了以下调用http://localhost:8081/actuator/health的响应:
{
"status": "DOWN",
"components": {
"db": {
"status": "UP",
"details": {
"database": "H2",
"validationQuery": "isValid()"
}
},
"diskSpace": {
"status": "UP",
"details": {
"total": 1022565265408,
"free": 861403496448,
"threshold": 10485760,
"path": "C:\\Users\\nick\\eclipse-workspace\\demoapp\\.",
"exists": true
}
},
"livenessState": {
"status": "DOWN"
},
"ping": {
"status": "UP"
},
"readinessState": {
"status": "OUT_OF_SERVICE"
}
},
"groups": [
"liveness",
"readiness"
]
}
我的pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>my.demo.springboot</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo SpringBoot</name>
<description>Demo Spring Boot Example</description>
<properties>
<java.version>17</java.version>
<log4j2.version>2.20.0</log4j2.version>
<netty.version>4.1.92.Final</netty.version>
<snakeyaml.version>2.0</snakeyaml.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.prettytime</groupId>
<artifactId>prettytime</artifactId>
<version>5.0.6.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我在官方文件中阅读到了以下内容:
预计在启动期间运行的任务应该由CommandLineRunner和ApplicationRunner组件执行,而不是使用Spring组件生命周期回调,如@PostConstruct。
但我没有修改任何行为,所以我目前不知道在哪里和什么寻找。
当我在kubernetes上运行时,我使用两个端点来监视我的应用程序,但现在它不断重新启动,因为两个健康检查都失败,并显示503。
我希望这只是一些简单的东西,我已经忘记/改变,任何人都知道或已经有这个问题。
如果需要更多的信息,请告诉我。
谢谢!
更新:
这只发生在Sping Boot 3.0.6中,而3.0.5运行正常:
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 1022565265408,
"free": 863173750784,
"threshold": 10485760,
"path": "C:\\<censored>\\.",
"exists": true
}
},
"livenessState": {
"status": "UP"
},
"mail": {
"status": "UP",
"details": {
"location": "<censored>.net:25"
}
},
"ping": {
"status": "UP"
},
"readinessState": {
"status": "UP"
}
},
"groups": [
"liveness",
"readiness"
]
}
GitHub上的issue可能与此相关。
1条答案
按热度按时间sirbozc51#
问题与GitHub问题35161有关。修复及其说明为:
启用延迟初始化时,活动和就绪探测器返回
更新到Sping Boot 版本3.1.0为我解决了这个问题(3.0.7也应该有修复,但从我这边未经测试),健康端点再次启动(3.1.0刚刚发布3天前)。
详细内容:
这是由#34347的更改引起的回归。@Bean方法的返回类型已从ApplicationAvailabilityBean更改为ApplicationAvailability。这意味着类型信息丢失,bean工厂无法判断它是ApplicationListener。