一般情况下这种问题基本都是,项目中设置的问题。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- war包部署移除嵌入式tomcat插件 --> <!--<exclusions>--> <!--<exclusion>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-tomcat</artifactId>--> <!--</exclusion>--> <!--</exclusions>--> </dependency>必须将内置tomcat注释掉,然后加入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>这个是终结版本。然后还需加入
<!-- war包部署添加servlet依赖 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>设置启动类
<configuration> <fork>true</fork> <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments> <mainClass>com.mtons.mblog.BootApplication</mainClass> </configuration>设置打包方式
<packaging>war</packaging>打包名称
<finalName>ROOT</finalName>启动类加入以下
package com.mtons.mblog; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.ApplicationContext; /** * SprintBootApplication */ @Slf4j @SpringBootApplication @EnableCaching public class BootApplication extends SpringBootServletInitializer { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(BootApplication.class, args); String serverPort = context.getEnvironment().getProperty("server.port"); log.info("mblog started at http://localhost:" + serverPort); } //为了打包springboot项目 @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder builder) { return builder.sources(BootApplication.class); } }然后点击打包,记得clean
将这个ROOT直接扔进Tomcat-webapps下面 把原来webapps下面文件夹全部删掉
然后去bin目录下直接启动tomcat,知道出现 以下图标就说明成功了
加群:687942640