springboot框架中常⽤模板搭建springboot框架导⼊依赖
<parent>
<groupId>org.springframework.boot</groupId>
springboot框架是干嘛的<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.23</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.23</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.0.RELEASE</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
zookeeper依赖
<dependency>
<groupId>keeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.6</version>
<exclusions>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
src/main/java
yml配置⽂件
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=db_calculation
username: root
password:123456
devtools:
restart:
enabled:true
additional-paths: src/main/java
exclude: WEB-INF/**
freemarker:
cache:false
src/test/java
依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
需要使⽤注解@RunWith(SpringJUnit4ClassRunner.class)和@SpringBootTest(classes = SpotCheckStartApplication.class)
import Test;
import RunWith;
import SpringBootTest;
import SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SpotCheckStartApplication.class)
public class SpotTest {
@Autowired
private SpotService spotService;
@Test
public void getAll(){
List<Item> spot = AllSpot();
for(Item item : spot){
System.out.println(item);
}
}
}
⽇志
配置⽂件
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true"scanPeriod="60 seconds"debug="false">
<!-- property ⽤于配置变量,可通过${LOG_PATH}取对应的值 a -->
<!-- 定义⽇志的存储地址,不要在配置中使⽤相对路径 -->
<property name="LOG_PATH"value="D:/Java Code/testmaven06calculation/log/"/>
<property name="PATTERN"value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level line:%line %logger{50} %msg%n"/> <contextName>logback</contextName>
<!-- 输出到控制台,⼀个appender定义⼀种输出策略,可以定义多个a -->
<appender name="console"class="ch.ConsoleAppender">
<!-- filter中定义要输出的⽇志级别,默认是info -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
<!-- ⽇志输出编码格式化 -->
<encoder>
<pattern>
${PATTERN}
</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 输出到⽂件debug,⽇期滚动记录a -->
<appender name="logDebugFile"class="ch.olling.RollingFileAppender">
<!--<Prudent>true</Prudent> -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤其他只留debug -->
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 滚动策略按照时间滚动TimeBasedRollingPolicy每天会⽣成⼀个⽇志⽂件a -->
<rollingPolicy class="ch.olling.TimeBasedRollingPolicy">
<!-- ⽂件路径定义了⽇志的切分⽅式防⽌⽇志填满磁盘 -->
<fileNamePattern>
${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.log
</fileNamePattern>
</fileNamePattern>
<!-- ⽇志保留天数 -->
<maxHistory>7</maxHistory>
<!-- ⽤来指定⽇志⽂件的上下限⼤⼩到了这个值就是删除旧⽇志 -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<append>true</append>
<!-- ⽇志输出编码格式化 -->
<encoder>
<charset>GBK</charset>
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<!-- 输出到⽂件info,⽇期滚动记录a -->
<appender name="logInfoFile"class="ch.olling.RollingFileAppender"> <!--<Prudent>true</Prudent> -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤其他只留info -->
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 滚动策略按照时间滚动TimeBasedRollingPolicy每天会⽣成⼀个⽇志⽂件a -->
<rollingPolicy class="ch.olling.TimeBasedRollingPolicy">
<!-- ⽂件路径定义了⽇志的切分⽅式防⽌⽇志填满磁盘 -->
<fileNamePattern>
${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- ⽇志保留天数 -->
<maxHistory>7</maxHistory>
<!-- ⽤来指定⽇志⽂件的上下限⼤⼩到了这个值就是删除旧⽇志 -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<append>true</append>
<!-- ⽇志输出编码格式化 -->
<encoder>
<charset>GBK</charset>
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<!-- 输出到⽂件WARN,⽇期滚动记录a -->
<appender name="logWarnFile"class="ch.olling.RollingFileAppender"> <!--<Prudent>true</Prudent> -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤其他只留info -->
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!-- 滚动策略按照时间滚动TimeBasedRollingPolicy每天会⽣成⼀个⽇志⽂件a -->
<rollingPolicy class="ch.olling.TimeBasedRollingPolicy">
<!-- ⽂件路径定义了⽇志的切分⽅式防⽌⽇志填满磁盘 -->
<fileNamePattern>
${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- ⽇志保留天数 -->
<maxHistory>7</maxHistory>
<!-- ⽤来指定⽇志⽂件的上下限⼤⼩到了这个值就是删除旧⽇志 -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<append>true</append>
<!-- ⽇志输出编码格式化 -->
<encoder>
<charset>GBK</charset>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。