Idea uses Spring Initalizr to quickly build spring Boot

  1. Click New Project and select as shown
  2. Click next after
  3. Click Next and choose as shown
  4. Choose the path
  5. Click Finish, as shown in the picture, delete what you don’t want, and the project is completed
  6. Build a Controller, start the project and see the results returned

Set up your own SpringBoot project on your own server

Pass the project to the remote service using IDEA

  1. Set up the idea
  2. Configuring Related Information
  3. Upload to the specified machine

Configure the startup script based on the java-jar command

  • start.sh
#! /bin/bash
nohup java -jar target/zplxjj.jar  &
Copy the code
  • stop.sh
#! /bin/bash
PID=$(ps -ef | grep target/zplxjj.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill $PID
fi
~
Copy the code
  • run.sh
#! /bin/bash
echo stop application
source stop.sh
echo start application
source start.sh
Copy the code

All you need to do to start your own project is execute run.sh, and you have your own Spring Boot setup

Logback configuration

In the actual project, we hope that the log can be recorded on the server. Here we use logback, which is provided by SpringBoot. My integration method is to add logback-spring. XML file and then start the project.

<?xml version="1.0" encoding="UTF-8"? >
<configuration>
    <! -- The tag that defines the value of a variable -->
    <property name="LOG_HOME" value="./logs"/>
    <property name="encoding" value="UTF-8"/>
    <! Format output: %d indicates the date, %thread indicates the thread name, %-5level: level displays 5 character widths from the left; %M:%L is the method and line number; % MSG is a log message; %n is a newline character -->
    <property name="normal-pattern"
              value="%d{yyyy-MM-dd/HH:mm:ss.SSS}|%X{localIp}|%X{requestId}|%X{requestSeq}|%X{country}|%X{deviceType}|%X{deviceId}|%X{userId} |^_^|[%t] %-5level %logger{50} %line - %m%n"/>
    <property name="plain-pattern" value="%d{yyyy-MM-dd.HH:mm:ss} %msg%n"/>

    <! Generate log files per day -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <! -- Log file output file name -->
        <file>${LOG_HOME}/zplxjj.log</file>
        <Append>true</Append>
        <prudent>false</prudent>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${normal-pattern}</pattern>
            <charset>${encoding}</charset>
        </encoder>
        <! -- Split by time -->
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/zplxjj.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>128MB</maxFileSize>
            <maxHistory>15</maxHistory>
            <totalSizeCap>32GB</totalSizeCap>
        </rollingPolicy>
    </appender>

    <! -- Console output -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <! Format output: %d indicates the date, %thread indicates the thread name, %-5level indicates the level of 5 characters from the left. % MSG indicates the log message, %n indicates the newline character.
            <pattern>${normal-pattern}</pattern>
        </encoder>
    </appender>

    <! -- log file error -->
    <appender name="ERROR"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <file>${LOG_HOME}/zplxjj-error.log</file>
        <prudent>false</prudent>
        <Append>true</Append>
        <encoder>
            <pattern>${normal-pattern}</pattern>
            <charset>${encoding}</charset>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/zplxjj-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>128MB</maxFileSize>
            <maxHistory>15</maxHistory>
            <totalSizeCap>32GB</totalSizeCap>
        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="ERROR"/>
    </root>
</configuration>

Copy the code

The effect is as follows:

I have also opened a wechat official account: Stonezplxjj and a personal blog: www.zplxjj.com. For more articles, please pay attention to the official account: