Tomcat adds Context configuration, which causes the project to be loaded twice at startup

1. In the scenario
eclipse publishes the web application to tomcat, the project name is required to access the project by default, for example http://localhost:8080/myapp/ .
Now you need to change it to visit http://localhost like this .
Modify the server.xml file of tomcat and add the following configuration . The <Context path="" docBase="myapp" reloadable="false"/>modified host part is as follows:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

       <Context path="" docBase="myapp" reloadable="false"/>

      </Host>

At this time, every time you start tomcat and observe the log, you will find that the application is loaded twice. What is the reason?

2. The cause of the problem

The problem caused by the virtual directory, we configured appBase="webapps" in the Host tag, and tomcat loads the application once. Configured docBase once, and tomcat loaded the application again.

3. Solutions

Set appBase="webapps" to appBase="" and docBase="myapp" to docBase="webapps/myapp". The configuration is as follows:

<Host name="localhost"  appBase=""
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

       <Context path="" docBase="webapps/myapp" reloadable="false"/>

      </Host>

Note: If the links or pictures in your project are written with absolute paths, the absolute path with the project name cannot be used.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325388275&siteId=291194637