springboot打包成war,部署到tomcat,访问404

一、打成war包发布到tomcat(这步已经完成,自行跳过)

1. pom.xml

去掉内嵌tomcat

`
     
        org.springframework.boot
        spring-boot-starter-tomcat
        provided
    
`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

打成war

`
    war
`
  • 1
  • 2
  • 3
  • 4

2. 启动类

`
    @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);
        }


    }

`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

mvn clean package 将war包放到tomcat下试试吧,如果报404,参考下面 
访问地址:localhost:{tomcat端口号} /重命名的war包名/xxxx


二、404解决办法

原因后续补充

1. pom.xml

`
    
        org.springframework.boot
        spring-boot-legacy
        1.1.0.RELEASE
    
`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2. 修改web.xml

复制下面的代码,修改com.yzker.test.application.Application为你自己的启动类

`
    
    

      
        contextConfigLocation
        com.yzker.test.application.Application
      

      
        org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
      

      

      
        appServlet
        org.springframework.web.servlet.DispatcherServlet
        
          contextAttribute
          org.springframework.web.context.WebApplicationContext.ROOT
        
        1
      

      
        appServlet
        /
      


`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

3. 到此为止,404的问题解决,如果还有问题,请评论,我们共同解决记录

mvn clean package 
将target目录下生成war包放到tomcat里吧 
访问地址:localhost:{tomcat端口号} /重命名的war包名/xxxx

你可能感兴趣的:(springboot打包成war,部署到tomcat,访问404)