第一步:在pom.xml文件添加依赖
<!-- tomcat provided表示编译时的依赖,运行时不添加这个依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
第二步:启动类继承SpringBootServletInitializer并重写configure方法
package com.jack.seckill;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder;
}
}
第三步:右击项目选择properties 找到项目路径
第四步:打开cmd进入该项目路径,输入mvn clean package
第五步:将war包复制到tomcat下面webapps的文件下面
第六步:启动tomcat
第七步:访问路径进行测试
原访问路径添加seckill名,才能访问成功
http://localhost:8080/seckill/login/to_login