我想在服务器启动时调用以下类。
AlertsData位于com.mongo.service:
public class AlertsData extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
alertingPoolsData();
}
}
的web.xml:
<servlet-mapping>
<servlet-name>AlertsData</servlet-name>
<display-name>AlertsData</display-name>
<servlet-class>com.mongo.service.AlertsData</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet-mapping>
得到以下错误:
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/lbmongo]]
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:785)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
这台服务器没有启动并且出现以下错误..一些请帮助:( 我想在服务器启动时调用AlertsData类。
答案 0 :(得分:0)
web.xml
中的servlet配置看起来无效。 servlet-class
和load-on-startup
等元素属于servlet
部分,而不属于servlet-mapping
部分。您应该同时拥有servlet
部分和servlet-mapping
部分,例如:
<servlet>
<servlet-name>AlertsData</servlet-name>
<display-name>AlertsData</display-name>
<servlet-class>com.mongo.service.AlertsData</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AlertsData</servlet-name>
<url-pattern>/alerts</url-pattern>
</servlet-mapping>
url-pattern
下的sevlet-mapping
是您要用来访问servlet的网址(用您自己的网址替换“/alerts
”。)