我在自动加载tomcat7时遇到问题。这是init.d脚本:

#!/bin/bash
# chkconfig: 2345 80 20
# Description: Tomcat Server basic start/shutdown script
# /etc/init.d/tomcat7 -- startup script for the Tomcat 7 servlet engine

TOMCAT_HOME=/usr/local/tomcat7/bin
START_TOMCAT=/usr/local/tomcat7/bin/startup.sh
STOP_TOMCAT=/usr/local/tomcat7/bin/shutdown.sh

start() {
 echo -n "Starting tomcat7: "
 cd $TOMCAT_HOME
 ${START_TOMCAT}
 echo "done."
}

stop() {
 echo -n "Shutting down tomcat7: "
 cd $TOMCAT_HOME
 ${STOP_TOMCAT}
 echo "done."
}

case "$1" in

start)
 start
 ;;

stop)
 stop
 ;;

restart)
 stop
 sleep 10
 start
 ;;

*)
 echo "Usage: $0 {start|stop|restart}"

esac
exit 0


像这样开始时:

>service tomcat7 start

Starting tomcat7:
Using CATALINA_BASE:   /usr/local/tomcat7
Using CATALINA_HOME:   /usr/local/tomcat7
Using CATALINA_TMPDIR: /usr/local/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.
done.


Tomcat似乎无法从apache commons加载属性文件。有人知道为什么是这样吗 ?

The file is:
user-config.properties
found in:
/usr/local/tomcat7/conf


直接运行时一切正常,如下所示:

/usr/local/tomcat7/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat7
Using CATALINA_HOME:   /usr/local/tomcat7
Using CATALINA_TMPDIR: /usr/local/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.


跑过,匆匆处理:

%>服务tomcat7启动
启动tomcat7:使用CATALINA_BASE:/ usr / local / tomcat7
使用CATALINA_HOME:/ usr / local / tomcat7
使用CATALINA_TMPDIR:/ usr / local / tomcat7 / temp
使用JRE_HOME:/ usr
使用CLASSPATH:/usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat启动。
完成。

%> ps -aux |grep tomcat
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root     26657 60.4  8.5 7181652 1385552 pts/0 Sl   16:11   0:15 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat7/endorsed -classpath /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat7 -Dcatalina.home=/usr/local/tomcat7 -Djava.io.tmpdir=/usr/local/tomcat7/temp org.apache.catalina.startup.Bootstrap start
root     26706  0.0  0.0 103252   844 pts/0    S+   16:11   0:00 grep tomcat


现在我加载网页导致错误

HTTP Status 500 - java.lang.ExceptionInInitializerError
type Exception report
message java.lang.ExceptionInInitializerError
description The server encountered an internal error that prevented it from fulfilling this request.
exception

javax.servlet.ServletException: java.lang.ExceptionInInitializerErrorcom.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)javax.servlet.http.HttpServlet.service(HttpServlet.java:727)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.ftw.tme.filter.SessionFilter.doFilter(SessionFilter.java:130)

root cause

java.lang.ExceptionInInitializerErrorcom.ftw.tme.authentication.service.impl.AuthenticationServiceImpl.<init>(AuthenticationServiceImpl.java:27)com.ftw.tme.rest.AuthenticationRestService.<init>(AuthenticationRestService.java:38)sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)java.lang.reflect.Constructor.newInstance(Constructor.java:526)com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:245)com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:233)com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:182)com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:144)com.sun.jersey.server.impl.application.WebApplicationContext.getResource(WebApplicationContext.java:239)com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)javax.servlet.http.HttpServlet.service(HttpServlet.java:727)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.ftw.tme.filter.SessionFilter.doFilter(SessionFilter.java:130)

root cause

java.lang.NullPointerExceptionjava.lang.String.replace(String.java:2180)com.ftw.tme.commons.db.util.tmeConfigUtils.<clinit>(tmeConfigUtils.java:71)com.ftw.tme.authentication.service.impl.AuthenticationServiceImpl.<init>(AuthenticationServiceImpl.java:27)com.ftw.tme.rest.AuthenticationRestService.<init>(AuthenticationRestService.java:38)sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)java.lang.reflect.Constructor.newInstance(Constructor.java:526)com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:245)com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:233)com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getInstance(PerRequestFactory.java:182)com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerRequest.getInstance(PerRequestFactory.java:144)com.sun.jersey.server.impl.application.WebApplicationContext.getResource(WebApplicationContext.java:239)com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)javax.servlet.http.HttpServlet.service(HttpServlet.java:727)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)com.ftw.tme.filter.SessionFilter.doFilter(SessionFilter.java:130)






%> ps -aux |grep tomcat
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root     26657 19.2  8.6 7718532 1397424 pts/0 Sl   16:11   0:15 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat7/endorsed -classpath /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat7 -Dcatalina.home=/usr/local/tomcat7 -Djava.io.tmpdir=/usr/local/tomcat7/temp org.apache.catalina.startup.Bootstrap start
root     26727  0.0  0.0 103252   844 pts/0    S+   16:12   0:00 grep tomcat
[user@localhost bin]#

最佳答案

在您自己的代码中看起来像NPE:

root cause

java.lang.NullPointerException
  java.lang.String.replace(String.java:2180)
  com.ftw.tme.commons.db.util.tmeConfigUtils.<clinit>(tmeConfigUtils.java:71)
  com.ftw.tme.authentication.service.impl.AuthenticationServiceImpl.<init>(AuthenticationServiceImpl.java:27)
  com.ftw.tme.rest.AuthenticationRestService.<init>(AuthenticationRestService.java:38)

关于java - Tomcat7 CentOS服务启动失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26733474/

10-10 01:13