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
This commit is contained in:
parent
3496f3f9dc
commit
45315a97ff
|
@ -25,6 +25,8 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
|
@ -50,6 +52,7 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo
|
|||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
@ -81,6 +84,8 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|||
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private static Log logger = LogFactory.getLog(EndpointWebMvcAutoConfiguration.class);
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
|
@ -184,8 +189,21 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
|||
}
|
||||
});
|
||||
}
|
||||
try {
|
||||
childContext.refresh();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// No support currently for deploying a war with management.port=<different>,
|
||||
// and this is the signature of that happening
|
||||
if (e instanceof EmbeddedServletContainerException
|
||||
|| e.getCause() instanceof EmbeddedServletContainerException) {
|
||||
logger.warn("Could not start embedded container (management endpoints are still available through JMX)");
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static enum ManagementServerPort {
|
||||
|
||||
|
|
Loading…
Reference in New Issue