sunnychayen
sunnychayen

Reputation: 434

Servlet context loading twice with tomcat

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 &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>

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.

Upvotes: 2

Views: 2626

Answers (1)

matt b
matt b

Reputation: 140011

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>.

Upvotes: 4

Related Questions