Skip to content

Commit 45315a9

Browse files
author
Dave Syer
committed
Prevent accidental failure of deployed war when management.port is set
We can't support (yet) embedded containers inside a deployed war (class loader conflicts are inevitable, really). Until we figure out a way to do it, we should just log a warning and advise the user to switch to JMX for the actuator endpoints. See gh-552
1 parent 3496f3f commit 45315a9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.servlet.http.HttpServletRequest;
2626
import javax.servlet.http.HttpServletResponse;
2727

28+
import org.apache.commons.logging.Log;
29+
import org.apache.commons.logging.LogFactory;
2830
import org.springframework.beans.BeansException;
2931
import org.springframework.beans.factory.BeanFactory;
3032
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -50,6 +52,7 @@
5052
import org.springframework.boot.autoconfigure.web.ServerProperties;
5153
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
5254
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
55+
import org.springframework.boot.context.embedded.EmbeddedServletContainerException;
5356
import org.springframework.context.ApplicationContext;
5457
import org.springframework.context.ApplicationContextAware;
5558
import org.springframework.context.ApplicationListener;
@@ -81,6 +84,8 @@
8184
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
8285
ApplicationListener<ContextRefreshedEvent> {
8386

87+
private static Log logger = LogFactory.getLog(EndpointWebMvcAutoConfiguration.class);
88+
8489
private ApplicationContext applicationContext;
8590

8691
@Autowired
@@ -184,7 +189,20 @@ public void onApplicationEvent(ContextClosedEvent event) {
184189
}
185190
});
186191
}
187-
childContext.refresh();
192+
try {
193+
childContext.refresh();
194+
}
195+
catch (RuntimeException e) {
196+
// No support currently for deploying a war with management.port=<different>,
197+
// and this is the signature of that happening
198+
if (e instanceof EmbeddedServletContainerException
199+
|| e.getCause() instanceof EmbeddedServletContainerException) {
200+
logger.warn("Could not start embedded container (management endpoints are still available through JMX)");
201+
}
202+
else {
203+
throw e;
204+
}
205+
}
188206
}
189207

190208
protected static enum ManagementServerPort {

0 commit comments

Comments
 (0)