(1) Modify the <packaging>war</packaging> file of pom.xml, which is the jar package by default. Add <finalName>springboot</finalName> to the <build> node, that is, the name of the war package is generated. The complete pom.xml file content is as follows:
<?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) Modify the project startup class and inherit the SpringBootServletInitializer, as follows:
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@EnableCachingpublic 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) Packaging: You can run as ->maven install through eclipse run as ->maven install, or you can enter the root directory of the project, that is, the same level directory as pom.xml, start the cmd console, and execute mvn install package, as follows:
(4) Environment construction (Linux environment JDK installation and Tomacat installation (springboot supports tomcat7 or above))
JDK installation reference: //www.VeVB.COM/LINUXjishu/66536.html
Tomcat installation reference://www.VeVB.COM/article/95272.htm
(5) Upload the packaged war package to the webapp directory under the tomcat directory and start the tomcat server.
(6) Access project path: http://ip address: port number/project packaging name/method name (project packaging name is the value of <finnalName> in pom.xml)
(7) Set to automatically start to tomcat on
(1) Modify the script file rc.local: vim /etc/rc.d/rc.local
(2) Add in rc.local: export JAVA_HOME = jdk installation path, tomcat installation path/bin/startup.sh start
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.