使用tomcat加载Servlet上下文两次

时间:2011-10-21 12:49:47

标签: java tomcat servlets

当我在conf/server.xml中指定了多个主机标签时,servlet上下文将加载两次。它是基于spring的Web应用程序。我已经扩展了弹簧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 &quot;%r&quot; %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 &quot;%r&quot; %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 &quot;%r&quot; %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

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:3)

这似乎应该是预期的行为 - 您已将Tomcat配置为运行应用程序两次,每个主机运行一次。你能指望什么?如果你想要运行一个webapp实例,那么你就不应该这样配置两个<host>s - 我相信你add a host name alias为单一/默认<Host>