Servlet上下文使用tomcat加载两次

发布于 2024-12-11 08:17:50 字数 2202 浏览 0 评论 0原文

当我在 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 &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

任何帮助将不胜感激。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩饰不了的爱 2024-12-18 08:17:50

这似乎应该是预期的行为 - 您已将 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>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文