Skip to content

Commit 5dcb926

Browse files
committed
fix: isolate HealthIndicator beans in static inner class with ConditionalOnClass to prevent NoClassDefFoundError when Actuator is not on classpath
1 parent 0f645a1 commit 5dcb926

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

python-embed-spring-boot-starter/src/main/java/io/github/howtis/pythonembed/spring/PythonEmbedAutoConfiguration.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,22 @@ public void destroy() {
149149
// HealthIndicator (auto-detected when Actuator is on classpath)
150150
// ------------------------------------------------------------------
151151

152-
@Bean
153-
@ConditionalOnMissingBean
154-
@ConditionalOnProperty(prefix = "python-embed", name = "mode", havingValue = "SINGLE", matchIfMissing = true)
152+
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
155153
@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator")
156-
PythonEmbedHealthIndicator pythonEmbedHealthIndicator(PythonEmbed embed) {
157-
return new PythonEmbedHealthIndicator.Single(embed);
158-
}
154+
static class HealthIndicatorConfiguration {
159155

160-
@Bean
161-
@ConditionalOnMissingBean
162-
@ConditionalOnProperty(prefix = "python-embed", name = "mode", havingValue = "POOL")
163-
@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator")
164-
PythonEmbedHealthIndicator pythonEmbedPoolHealthIndicator(PythonEmbedPool pool) {
165-
return new PythonEmbedHealthIndicator.Pool(pool);
156+
@Bean
157+
@ConditionalOnMissingBean
158+
@ConditionalOnProperty(prefix = "python-embed", name = "mode", havingValue = "SINGLE", matchIfMissing = true)
159+
PythonEmbedHealthIndicator pythonEmbedHealthIndicator(PythonEmbed embed) {
160+
return new PythonEmbedHealthIndicator.Single(embed);
161+
}
162+
163+
@Bean
164+
@ConditionalOnMissingBean
165+
@ConditionalOnProperty(prefix = "python-embed", name = "mode", havingValue = "POOL")
166+
PythonEmbedHealthIndicator pythonEmbedPoolHealthIndicator(PythonEmbedPool pool) {
167+
return new PythonEmbedHealthIndicator.Pool(pool);
168+
}
166169
}
167170
}

0 commit comments

Comments
 (0)