"Sinkholes" springboot packaged into war, deployed to Tomcat, access 404

Source: Internet
Author: User
The pit is so deep that I can't breathe. as the friends said, I removed springboot embedded tomcat, and then rely on SERVLET-API, modify the start class to inherit Springbootservletinitializer, fight into a war into Tomcat but ..... Visit newspaper 404

this could be a split line . One, the war package released to Tomcat (this step has been completed, skipped) 1. Pom.xml

Remove inline Tomcat

'
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId> spring-boot-starter-tomcat</artifactid>
        <scope>provided</scope><!--Open a comment when it's war Local development with inline Tomcat plus annotation-->
    </dependency>
'

Make War

'
    <packaging>war</packaging>
'
2. Start class
'
    @SpringBootApplication
    @ComponentScan (basepackages = "Com.yzker") Public
    class application extends Springbootservletinitializer {

        @Override
        protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {return
            application.sources (application.class);
        }

        public static void Main (string[] args) {
            springapplication.run (application.class, args);
        }

`

MVN Clean Package put the war package under Tomcat and try it, if you report 404, refer to the following
Access address: Localhost:{tomcat port number}/renamed War package name/xxxx two, 404 Solutions

reasons for subsequent additions 1. Pom.xml

'
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId> spring-boot-legacy</artifactid>
        <version>1.1.0.RELEASE</version>
    </dependency >
'
2. Modify Web.xml

Copy the following code and modify the Com.yzker.test.application.Application for your own startup class

' <?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee htt P://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <context-param> <param-name>contextconfiglo Cation</param-name> <param-value>com.yzker.test.application.Application</param-value> < /context-param> <listener> <listener-class>org.springframework.boot.legacy.context.web.sprin
              Gbootcontextloaderlistener</listener-class> </listener> <!--<filter> <filter-name>metricFilter</filter-name> <filter-class>org.springframework.web.filter . delegatingfilterproxy</filter-class> </filter> <filter-mapping> <f Ilter-name>metricfilTer</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>-- > <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.s Pringframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name> Contextattribute</param-name> <param-value>org.springframework.web.context.webapplicationcontext.ro ot</param-value> </init-param> <load-on-startup>1</load-on-startup> </ser vlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-patter
 n>/</url-pattern> </servlet-mapping> </web-app> '
3. So far, 404 of the problem solved, if there are problems, please comment, we jointly resolve the record

MVN Clean Package
Put the build war package in the target directory into Tomcat.
Access address: Localhost:{tomcat port number}/renamed War package name/xxxx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.