(1)pom.xml文件修改<packaging>war</packaging>,默認是jar包,<build>節點中增長<finalName>springboot</finalName>,即生成war包的名字,完整pom.xml文件內容以下:html
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>springboot</groupId> <artifactId>springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>springboot</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <version>1.3.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> </dependencies> <build> <finalName>springboot</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
(2)修改項目啓動類,繼承SpringBootServletInitializer,以下:java
package springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling @EnableCaching public class SpringbootApplication extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(SpringbootApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SpringbootApplication.class); } }
(3)打包:能夠經過eclipse run as ->maven install,也能夠進入項目的根目錄,也就是pom.xml同一級目錄,啓動cmd控制檯,執行mvn install package,以下:mysql
(4)環境搭建(linux環境JDK安裝與Tomacat安裝(springboot支持tomcat7以上))linux
JDK安裝參考:https://jingyan.baidu.com/article/ab0b56308966acc15afa7d18.htmlweb
Tomcat安裝參考:https://jingyan.baidu.com/article/27fa73268002f246f9271f45.htmlredis
(5)將打包好的war包上傳至tomcat目錄下webapp目錄下,啓動tomcat服務器。spring
(6)訪問項目路徑:http://ip地址:端口號/項目打包名稱/方法名(項目打包名稱即pom.xml中的<finnalName>的值)sql
(7)設置tomcat開機自動啓動apache
(1)修改腳本文件rc.local:vim /etc/rc.d/rc.localvim
(2)在rc.local中增長:export JAVA_HOME = jdk安裝路徑 ,tomcat安裝路徑/bin/startup.sh start