From 00cb6444de199e6590358d269e58a16b64543cbb Mon Sep 17 00:00:00 2001
From: "yangkai.shen" <237497819@qq.com>
Date: Fri, 10 Nov 2017 14:29:53 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 4 +
readme.md | 0
spring-boot-demo-helloworld/pom.xml | 24 ++++++
.../SpringBootDemoHelloworldApplication.java | 43 +++++++++++
.../src/main/resources/application.yml | 12 +++
...ingBootDemoHelloworldApplicationTests.java | 16 ++++
spring-boot-demo-logback/pom.xml | 54 +++++++++++++
.../SpringBootDemoLogbackApplication.java | 27 +++++++
.../src/main/resources/application.yml | 6 ++
.../src/main/resources/logback-spring.xml | 49 ++++++++++++
...SpringBootDemoLogbackApplicationTests.java | 16 ++++
spring-boot-demo-mybatis/pom.xml | 43 +++++++++++
.../SpringBootDemoMybatisApplication.java | 12 +++
.../src/main/resources/application.yml | 48 ++++++++++++
.../src/main/resources/init-sql/schema.sql | 19 +++++
...SpringBootDemoMybatisApplicationTests.java | 16 ++++
spring-boot-demo-parent/pom.xml | 76 +++++++++++++++++++
17 files changed, 465 insertions(+)
create mode 100644 .gitignore
create mode 100644 readme.md
create mode 100644 spring-boot-demo-helloworld/pom.xml
create mode 100644 spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java
create mode 100644 spring-boot-demo-helloworld/src/main/resources/application.yml
create mode 100644 spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java
create mode 100644 spring-boot-demo-logback/pom.xml
create mode 100644 spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java
create mode 100644 spring-boot-demo-logback/src/main/resources/application.yml
create mode 100644 spring-boot-demo-logback/src/main/resources/logback-spring.xml
create mode 100644 spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java
create mode 100644 spring-boot-demo-mybatis/pom.xml
create mode 100644 spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java
create mode 100644 spring-boot-demo-mybatis/src/main/resources/application.yml
create mode 100644 spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql
create mode 100644 spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java
create mode 100644 spring-boot-demo-parent/pom.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a793265
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.idea/
+*.iml
+logs/
+target/
\ No newline at end of file
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..e69de29
diff --git a/spring-boot-demo-helloworld/pom.xml b/spring-boot-demo-helloworld/pom.xml
new file mode 100644
index 0000000..8ab8afe
--- /dev/null
+++ b/spring-boot-demo-helloworld/pom.xml
@@ -0,0 +1,24 @@
+
+
+ 4.0.0
+
+ spring-boot-demo-helloworld
+ 0.0.1-SNAPSHOT
+ war
+
+ spring-boot-demo-helloworld
+ Demo project for Spring Boot
+
+
+ com.xkcoding
+ spring-boot-demo-parent
+ 0.0.1-SNAPSHOT
+ ../spring-boot-demo-parent/pom.xml
+
+
+
+ spring-boot-demo-helloworld
+
+
+
diff --git a/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java b/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java
new file mode 100644
index 0000000..b309446
--- /dev/null
+++ b/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java
@@ -0,0 +1,43 @@
+package com.xkcoding.springbootdemohelloworld;
+
+import com.google.common.collect.*;
+import com.xiaoleilu.hutool.util.StrUtil;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@SpringBootApplication
+@Configuration
+public class SpringBootDemoHelloworldApplication {
+ @Value("${spring.boot.demo.helloworld.data.version}")
+ private String version;
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDemoHelloworldApplication.class, args);
+ }
+
+ @GetMapping("/hello")
+ public Map sayHello(@Value("${author}") String author, @Value("${exclusions}") String exclusions, @Value("${connectionProperties}") String connectionProperties) {
+ Map result = Maps.newHashMap();
+ result.put("ret", true);
+ result.put("msg", StrUtil.format("hello,world,{}", author));
+ Map data = Maps.newHashMap();
+ data.put("version", version);
+ data.put("exclusions", exclusions.split(","));
+ Map connectionProperty = Maps.newHashMap();
+ for (String connection : connectionProperties.split(";")) {
+ String[] conn = connection.split("=");
+ connectionProperty.put(conn[0], conn[1]);
+ }
+ data.put("connectionProperties", connectionProperty);
+ result.put("data", data);
+ return result;
+ }
+}
diff --git a/spring-boot-demo-helloworld/src/main/resources/application.yml b/spring-boot-demo-helloworld/src/main/resources/application.yml
new file mode 100644
index 0000000..1905f0c
--- /dev/null
+++ b/spring-boot-demo-helloworld/src/main/resources/application.yml
@@ -0,0 +1,12 @@
+server:
+ port: 8080
+ context-path: /demo
+spring:
+ boot:
+ demo:
+ helloworld:
+ data:
+ version: 1.0.0
+author: xkcoding
+exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
+connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
\ No newline at end of file
diff --git a/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java b/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java
new file mode 100644
index 0000000..9d3de5c
--- /dev/null
+++ b/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java
@@ -0,0 +1,16 @@
+package com.xkcoding.springbootdemohelloworld;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringBootDemoHelloworldApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/spring-boot-demo-logback/pom.xml b/spring-boot-demo-logback/pom.xml
new file mode 100644
index 0000000..d212805
--- /dev/null
+++ b/spring-boot-demo-logback/pom.xml
@@ -0,0 +1,54 @@
+
+
+ 4.0.0
+
+ com.xkcoding
+ spring-boot-demo-logback
+ 0.0.1-SNAPSHOT
+ jar
+
+ spring-boot-demo-logback
+ Demo project for Spring Boot
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.8.RELEASE
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.projectlombok
+ lombok
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+
diff --git a/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java b/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java
new file mode 100644
index 0000000..887b847
--- /dev/null
+++ b/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java
@@ -0,0 +1,27 @@
+package com.xkcoding.springbootdemologback;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+
+@SpringBootApplication
+@Slf4j
+public class SpringBootDemoLogbackApplication {
+
+ public static void main(String[] args) {
+ ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoLogbackApplication.class, args);
+ int length = context.getBeanDefinitionNames().length;
+ log.trace("Spring boot启动初始化了 {} 个 Bean", length);
+ log.debug("Spring boot启动初始化了 {} 个 Bean", length);
+ log.info("Spring boot启动初始化了 {} 个 Bean", length);
+ log.warn("Spring boot启动初始化了 {} 个 Bean", length);
+ log.error("Spring boot启动初始化了 {} 个 Bean", length);
+ try {
+ int i = 0;
+ int j = 1 / i;
+ } catch (Exception e) {
+ log.error("【SpringBootDemoLogbackApplication】启动异常:", e);
+ }
+ }
+}
diff --git a/spring-boot-demo-logback/src/main/resources/application.yml b/spring-boot-demo-logback/src/main/resources/application.yml
new file mode 100644
index 0000000..e8db9e6
--- /dev/null
+++ b/spring-boot-demo-logback/src/main/resources/application.yml
@@ -0,0 +1,6 @@
+server:
+ port: 8080
+ context-path: /demo
+spring:
+ application:
+ name: logback-demo
\ No newline at end of file
diff --git a/spring-boot-demo-logback/src/main/resources/logback-spring.xml b/spring-boot-demo-logback/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..014e9cb
--- /dev/null
+++ b/spring-boot-demo-logback/src/main/resources/logback-spring.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+ 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
+
+
+
+
+
+
+
+
+ ${user.dir}/logs/log/logback-demo.%d.log
+
+
+ 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n
+
+
+
+
+
+ ERROR
+ ACCEPT
+ DENY
+
+
+
+
+ ${user.dir}/logs/error/logback-demo.%d.error
+
+
+ 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java b/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java
new file mode 100644
index 0000000..d3bf455
--- /dev/null
+++ b/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java
@@ -0,0 +1,16 @@
+package com.xkcoding.springbootdemologback;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringBootDemoLogbackApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/spring-boot-demo-mybatis/pom.xml b/spring-boot-demo-mybatis/pom.xml
new file mode 100644
index 0000000..f61a508
--- /dev/null
+++ b/spring-boot-demo-mybatis/pom.xml
@@ -0,0 +1,43 @@
+
+
+ 4.0.0
+
+ spring-boot-demo-mybatis
+ 0.0.1-SNAPSHOT
+ war
+
+ spring-boot-demo-mybatis
+ Demo project for Spring Boot
+
+
+ com.xkcoding
+ spring-boot-demo-parent
+ 0.0.1-SNAPSHOT
+ ../spring-boot-demo-parent/pom.xml
+
+
+
+ 1.3.1
+ 1.1.5
+
+
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ ${mybatis.starter.version}
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ ${druid.starter.version}
+
+
+
+
+ spring-boot-demo-mybatis
+
+
+
+
diff --git a/spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java b/spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java
new file mode 100644
index 0000000..cfa979e
--- /dev/null
+++ b/spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java
@@ -0,0 +1,12 @@
+package com.xkcoding.springbootdemomybatis;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootDemoMybatisApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDemoMybatisApplication.class, args);
+ }
+}
diff --git a/spring-boot-demo-mybatis/src/main/resources/application.yml b/spring-boot-demo-mybatis/src/main/resources/application.yml
new file mode 100644
index 0000000..3aa2478
--- /dev/null
+++ b/spring-boot-demo-mybatis/src/main/resources/application.yml
@@ -0,0 +1,48 @@
+server:
+ port: 8080
+ context-path: /demo
+spring:
+ datasource:
+ schema: classpath:init-sql/schema.sql
+ continue-on-error: true
+ druid:
+ url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
+ username: root
+ password: root
+ driver-class-name: com.mysql.jdbc.Driver
+ # 连接池配置
+ # 初始化大小,最小,最大
+ initialSize: 5
+ minIdle: 5
+ maxActive: 20
+ # 配置获取连接等待超时的时间
+ maxWait: 60000
+ # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+ timeBetweenEvictionRunsMillis: 60000
+ # 配置一个连接在池中最小生存的时间,单位是毫秒
+ minEvictableIdleTimeMillis: 300000
+ validationQuery: SELECT 1 FROM DUAL
+ testWhileIdle: true
+ testOnBorrow: false
+ testOnReturn: false
+ # 打开PSCache,并且指定每个连接上PSCache的大小
+ poolPreparedStatements: true
+ maxPoolPreparedStatementPerConnectionSize: 20
+ # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+ filters: stat,wall,log4j
+ # 监控配置
+ web-stat-filter:
+ enabled: true
+ url-pattern: /*
+ exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
+ stat-view-servlet:
+ enabled: true
+ url-pattern: /sys/druid/*
+ reset-enable: fasle
+ login-username: xkcoding
+ login-password: 123456
+ filter:
+ stat:
+ log-slow-sql: true
+ slow-sql-millis: 5000
+ merge-sql: true
\ No newline at end of file
diff --git a/spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql b/spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql
new file mode 100644
index 0000000..568908d
--- /dev/null
+++ b/spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql
@@ -0,0 +1,19 @@
+SET FOREIGN_KEY_CHECKS=0;
+
+-- ----------------------------
+-- Table structure for `boot_user`
+-- ----------------------------
+DROP TABLE IF EXISTS `mybatis_user`;
+CREATE TABLE `mybatis_user` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(32) DEFAULT NULL,
+ `tel` varchar(11) DEFAULT NULL,
+ `create_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+
+-- ----------------------------
+-- Records of boot_user
+-- ----------------------------
+INSERT INTO `mybatis_user` VALUES ('1', 'klay', '13799008800', '2016-06-27 00:01:39');
+INSERT INTO `mybatis_user` VALUES ('2', 'Tome', '18988991234', '2016-06-27 00:35:28');
diff --git a/spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java b/spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java
new file mode 100644
index 0000000..df6892d
--- /dev/null
+++ b/spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java
@@ -0,0 +1,16 @@
+package com.xkcoding.springbootdemomybatis;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringBootDemoMybatisApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/spring-boot-demo-parent/pom.xml b/spring-boot-demo-parent/pom.xml
new file mode 100644
index 0000000..2f88c9d
--- /dev/null
+++ b/spring-boot-demo-parent/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+
+ com.xkcoding
+ spring-boot-demo-parent
+ 0.0.1-SNAPSHOT
+ pom
+
+ spring-boot-demo-parent
+ Demo project for Spring Boot
+
+
+ ../spring-boot-demo-helloworld
+ ../spring-boot-demo-logback
+ ../spring-boot-demo-mybatis
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.8.RELEASE
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ mysql
+ mysql-connector-java
+
+
+
+ com.xiaoleilu
+ hutool-all
+ 3.1.2
+
+
+ com.google.guava
+ guava
+ 20.0
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+