您好我使用以下课程:
请注意,不是实现 ServletContextInitializer ,而是实现 WebApplicationInitializer ,以便它自动引导并由Tomcat *服务器启动。
但是我在日志中遇到以下错误:
javax.servlet.ServletException: Couldn't find a HealthCheckRegistry instance.
at com.codahale.metrics.servlets.HealthCheckServlet.init(HealthCheckServlet.java:74)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1044)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
我认为问题是由于applicationContext未在overriden方法之前初始化:
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// log.info("Web application configuration, using profiles: {}", Arrays.toString(env.getActiveProfiles()));
EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
initMetrics(servletContext, disps);
initUrlRewriteProductionFilter(servletContext, disps);
initCachingHttpHeadersFilter(servletContext, disps);
initGzipFilter(servletContext, disps);
log.info("Web application fully configured");
}
我做错了什么?