1、首先,修改pom.xml文件
<packaging>war
</packaging>
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-web
</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-tomcat
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet
</groupId>
<artifactId>javax.servlet-api
</artifactId>
<version>3.1.0
</version>
<scope>provided
</scope>
</dependency>
2、然后,修改主启动类
有两种方式,都可以
1)、直接在主启动类上继承SpringBootServletInitializer类,并实现configure方法
@MapperScan("com.zyh.blog.dao")
@SpringBootApplication
public class BlogMybatisPlusApplication extends SpringBootServletInitializer{
public static void main(String
[] args
) {
SpringApplication
.run(BlogMybatisPlusApplication
.class, args
);
}
@Override
protected SpringApplicationBuilder
configure(SpringApplicationBuilder builder
) {
return super.configure(builder
);
}
}
2)、在主启动类同级目录下创建一个类继承该方法
3、再者,就是clean、install,target目录下就会有对应的war包
4、最后,将项目打成的war包放到服务器Tomcat的/webapps/目录下,修改nginx配置文件
server
{
listen 80
;
server_name localhost
;
location
/blog
{
proxy_pass http:
//xx
.xx
.xx
.xx:8080
;
}
}
访问:http://xx.xx.xx.xx/blog/即可