今天复制一个新项目过程中犯了一个低级错误,记录下来,以示警戒:
复制了项目,复制了配置文件,修改了service name,启动tomcat,报错如下:
严重: Creation of the naming context failed: javax.naming.OperationNotSupportedException: Context is read only
javax.naming.NameNotFoundException: Name [comp/env/testService] is not bound in this Context. Unable to find [comp].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.jerehnet.util.dbutil.DBHelper.<clinit>(DBHelper.java:55)
at com.jerehnet.manage.ApplicationListener.getCategoryMapGift(ApplicationListener.java:82)
at com.jerehnet.manage.ApplicationListener.contextInitialized(ApplicationListener.java:29)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
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.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
调查才发现配置文件有错误:
原:
<Service name="test">
<Connector port="1111" maxHttpHeaderSize="8192"
maxThreads="2048" minSpareThreads="125" maxSpareThreads="475"
enableLookups="false" redirectPort="8443" acceptCount="800"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/>
<Engine name="test" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="E:\workspace\test\WebRoot" debug="5" reloadable="false" crossContext="true">
<Resource name="web21gift" auth="Container" type="javax.sql.DataSource" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/test;useLOBs=false" username="sa" password="sa123" maxActive="200" maxIdle="10" maxWait="-1"/>
<Resource name="web21service" auth="Container" type="javax.sql.DataSource" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/testService;useLOBs=false" username="sa" password="sa123" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>
</Host>
</Engine>
</Service>
复制新的:
<Service name="test2">
<Connector port="1111" maxHttpHeaderSize="8192"
maxThreads="2048" minSpareThreads="125" maxSpareThreads="475"
enableLookups="false" redirectPort="8443" acceptCount="800"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/>
<Engine name="test" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host name="localhost" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="E:\workspace\test2\WebRoot" debug="5" reloadable="false" crossContext="true">
<Resource name="web21gift" auth="Container" type="javax.sql.DataSource" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/test;useLOBs=false" username="sa" password="sa123" maxActive="200" maxIdle="10" maxWait="-1"/>
<Resource name="web21service" auth="Container" type="javax.sql.DataSource" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost:1433/testService;useLOBs=false" username="sa" password="sa123" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>
</Host>
</Engine>
</Service>
错误就是只修改了server name
<Service name="test2">
而没有 修改
Engine name
如下调整后问题解决,如果你也是这个错误,可以尝试看看是不是这种问题!
<Service name="test2">
<Connector port="1111" maxHttpHeaderSize="8192"
maxThreads="2048" minSpareThreads="125" maxSpareThreads="475"
enableLookups="false" redirectPort="8443" acceptCount="800"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8"/>
<Engine name="test2" defaultHost="localhost">