Cloud server deployment of SpringBoot project

1. Scene restoration

     Springboot configuration is fairly simple and everyone knows it. How to deploy the springboot project to the cloud server? Some people may say that the blogger, your previous article did not talk about the cloud deployment of java projects; but I want to clarify that the projects in my previous article are all built by the ssm framework, and springboot has its own tomcat! It's a bit of a hassle.... calm down and look down

2. Configuration parsing

①application.properties file

# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.port=8010
server.session-timeout=1800
server.context-path=
server.tomcat.max-threads=0
server.tomcat.uri-encoding=UTF-8
server.tomcat.basedir=target/tomcat

# HTTP encoding (HttpEncodingProperties)
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

#datasource
spring.datasource.url=jdbc:mysql://192.168.0.129/ccoee?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=zhangxing
spring.datasource.password=zxp52077
spring.datasource.driverClassName=com.mysql.jdbc.Driver

#mybatis
mybatis.type-aliases-package=com.cckj.model
mybatis.mapper-locations=classpath:mapper/*.xml

#mapper
mapper.mappers=tk.mybatis.mapper.common.Mapper
mapper.not-empty=false
mapper.identity=MYSQL

#pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

#logging
#logging.level.root=INFO
#logging.level.org.springframework.web=DEBUG
logging.level.org.zhangxing=DEBUG

 

It is this file that contains the cumbersome configuration of the ssm framework, which programmer doesn't love it? So if you love it, please love it! Configure the remote database connection, which will not be repeated here.

②pom.xml

 

<?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>
  <packaging>jar</packaging>
  <groupId>magic</groupId>
  <artifactId>magic</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.10</version>
    </dependency>

    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.1.1</version>
    </dependency>

    <dependency>
      <groupId>tk.mybatis</groupId>
      <artifactId>mapper-spring-boot-starter</artifactId>
      <version>1.0.0</version>
    </dependency>

    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.0.0</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>helloworld</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <id>spring-milestone</id>
      <url>http://repo.spring.io/libs-release</url>
    </repository>
  </repositories>

</project>

It should be noted here that the packaging method is jar, no longer war.

 

 

<packaging>jar</packaging>

custom package name

 

 

<build>
    <finalName>helloworld</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <id>spring-milestone</id>
      <url>http://repo.spring.io/libs-release</url>
    </repository>
  </repositories>

③Application startup class code

 

@SpringBootApplication
@MapperScan(basePackages = "com.cckj.dao", markerInterface =Mapper.class)
public class Application {


    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

 

Note: It is best to comment out the test main function in each method!

3. Implementation plan

Preparations: Before deployment, first confirm whether the cloud server is installed with the tomcat environment, and the service is turned on! If there is no environment, please install and start the service by yourself

①Start to make the jar package

Like the previous steps, click on the Maven Project on the right, click on Lifecycle, and finally double-click on the packet to generate the jar package

②Upload the jar you just typed to the java directory of the cloud server

③Run the command: java -jar helloworld.jar, then the built-in tomcat of the springboot project is turned on

Note: After deployment, you need to open port numbers: 3306, 8089

Access effect:

This is not over yet. Of course, when you close the current xshell command interface, the access will be invalid again. This is because the built-in tomcat of springboot is also closed, so some people will ask, what is cloud deployment called? Same as local, yeah, I think so too; don't worry, look down

④ Resident cloud server

Run the command: nohup java -jar helloworld.jar &

nohup means no service, resident means, unless the cloud server is restarted, it will be impossible; the last & means that the log file nohup.out will be generated after the command is executed

Well, then you don't have to worry about closing xshell, as long as the cloud server is not closed, you can always access it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325230434&siteId=291194637