Springboot 采用war包启动,仅需在启动类中添加如下所示的代码即可:
1 package com.fanfengping; 2 3 import org.mybatis.spring.annotation.MapperScan; 4 import org.springframework.boot.SpringApplication; 5 import org.springframework.boot.autoconfigure.SpringBootApplication; 6 import org.springframework.boot.builder.SpringApplicationBuilder; 7 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 8 9 @SpringBootApplication 10 @MapperScan("com.fanfengping.mapper") 11 public class SpringbootAdminApplication extends SpringBootServletInitializer { 12 13 public static void main(String[] args) { 14 SpringApplication.run(SpringbootAdminApplication.class, args); 15 } 16 17 @Override 18 public SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 19 return builder.sources(SpringbootAdminApplication.class); 20 } 21 }
在工程项目文件中,修改包输出方式为 war 包并重命名war包名字为 api.war,如下所示:
1 <groupId>com.fanfengping</groupId> 2 <artifactId>springboot-demo</artifactId> 3 <version>1.0.0</version> 4 <name>springboot-demo</name> 5 <description>Springboot WAR 启动配置</description> 6 <packaging>war</packaging> 7 8 9 <build> 10 <finalName>api</finalName> 11 <plugins> 12 <plugin> 13 <groupId>org.springframework.boot</groupId> 14 <artifactId>spring-boot-maven-plugin</artifactId> 15 </plugin> 16 </plugins> 17 </build>
执行命令:mvn clean package 将打包后的war包放到tomcat/webapps,启动tomcat,访问:http://127.0.0.1:8080/api/ 即可。