Servlet上下文使用tomcat加载两次
当我在 conf/server.xml
中指定多个主机标记时,servlet 上下文将加载两次。它是基于 spring
的 Web 应用程序。我扩展了 spring ContextLoader 并对其进行了自定义。
我的 server.xml (tomcat 7.0.22)
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
<Host name="domain.com" appBase="webapps/Domain"
unpackWARs="true" autoDeploy="true"
>
<Context path="" docBase="."/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
<Context docBase="/mnt/databank/posters" path="/Domain/posters"/>
<Context docBase="/mnt/databank/advertisement" path="/Domain/advertisement"/>
<Context docBase="/mnt/databank/star" path="/Domain/star"/>
</Host>
<Host name="www.domain.com" appBase="webapps/Redirecter"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="."/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
我在 ContextLoader 中添加了一个日志,它触发两次,如下所示,
2011-10-21 12:11:22,933 ERROR [Thread-2] c.i.b.u.DomainUtilInitializer [DomainUtilInitializer.java:38] Init Method Triggered
2011-10-21 12:11:46,621 ERROR [Thread-15] c.i.b.u.DomainUtilInitializer [DomainUtilInitializer.java:38] Init Method Triggered
任何帮助将不胜感激。
When I have specified multiple host tags in the conf/server.xml
, the servlet context is loading twice. It is spring
based web application. I have extended the spring ContextLoader
and customize it.
My server.xml (tomcat 7.0.22)
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
<Host name="domain.com" appBase="webapps/Domain"
unpackWARs="true" autoDeploy="true"
>
<Context path="" docBase="."/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
<Context docBase="/mnt/databank/posters" path="/Domain/posters"/>
<Context docBase="/mnt/databank/advertisement" path="/Domain/advertisement"/>
<Context docBase="/mnt/databank/star" path="/Domain/star"/>
</Host>
<Host name="www.domain.com" appBase="webapps/Redirecter"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="."/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/mnt/databank/logs/tomcat7"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
I have added a log in the ContextLoader it trigering twice as follows,
2011-10-21 12:11:22,933 ERROR [Thread-2] c.i.b.u.DomainUtilInitializer [DomainUtilInitializer.java:38] Init Method Triggered
2011-10-21 12:11:46,621 ERROR [Thread-15] c.i.b.u.DomainUtilInitializer [DomainUtilInitializer.java:38] Init Method Triggered
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎应该是预期的行为 - 您已将 Tomcat 配置为运行应用程序两次,每个主机运行一次。你期望什么?如果您希望运行 Web 应用程序的单个实例,那么您不应该像这样配置两个
- 我相信您 向单个/默认
添加主机名别名。This seems like it should be expected behavior - you have configured Tomcat to run the application twice, once for each host. What do you expect? If you want a single instance of the webapp running, then you shouldn't configure two
<host>s
like so - I believe you add a host name alias to the single/default<Host>
.