Browse Source

初始化提交

v-1.5.x
yangkai.shen 6 years ago
commit
00cb6444de
17 changed files with 465 additions and 0 deletions
  1. +4
    -0
      .gitignore
  2. +0
    -0
      readme.md
  3. +24
    -0
      spring-boot-demo-helloworld/pom.xml
  4. +43
    -0
      spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java
  5. +12
    -0
      spring-boot-demo-helloworld/src/main/resources/application.yml
  6. +16
    -0
      spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java
  7. +54
    -0
      spring-boot-demo-logback/pom.xml
  8. +27
    -0
      spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java
  9. +6
    -0
      spring-boot-demo-logback/src/main/resources/application.yml
  10. +49
    -0
      spring-boot-demo-logback/src/main/resources/logback-spring.xml
  11. +16
    -0
      spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java
  12. +43
    -0
      spring-boot-demo-mybatis/pom.xml
  13. +12
    -0
      spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java
  14. +48
    -0
      spring-boot-demo-mybatis/src/main/resources/application.yml
  15. +19
    -0
      spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql
  16. +16
    -0
      spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java
  17. +76
    -0
      spring-boot-demo-parent/pom.xml

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
.idea/
*.iml
logs/
target/

+ 0
- 0
readme.md View File


+ 24
- 0
spring-boot-demo-helloworld/pom.xml View File

@@ -0,0 +1,24 @@
<?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>

<artifactId>spring-boot-demo-helloworld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-demo-helloworld</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<build>
<finalName>spring-boot-demo-helloworld</finalName>
</build>

</project>

+ 43
- 0
spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java View File

@@ -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<String, Object> result = Maps.newHashMap();
result.put("ret", true);
result.put("msg", StrUtil.format("hello,world,{}", author));
Map<String, Object> data = Maps.newHashMap();
data.put("version", version);
data.put("exclusions", exclusions.split(","));
Map<String, Object> 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;
}
}

+ 12
- 0
spring-boot-demo-helloworld/src/main/resources/application.yml View File

@@ -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

+ 16
- 0
spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java View File

@@ -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() {
}

}

+ 54
- 0
spring-boot-demo-logback/pom.xml View File

@@ -0,0 +1,54 @@
<?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>com.xkcoding</groupId>
<artifactId>spring-boot-demo-logback</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-boot-demo-logback</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.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.8</java.version>
</properties>

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

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

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

+ 27
- 0
spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java View File

@@ -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);
}
}
}

+ 6
- 0
spring-boot-demo-logback/src/main/resources/application.yml View File

@@ -0,0 +1,6 @@
server:
port: 8080
context-path: /demo
spring:
application:
name: logback-demo

+ 49
- 0
spring-boot-demo-logback/src/main/resources/logback-spring.xml View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<conversionRule conversionWord="clr"
converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>

<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>【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}
</pattern>
</layout>
</appender>

<appender name="fileLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--输出路径-->
<fileNamePattern>${user.dir}/logs/log/logback-demo.%d.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--输出路径-->
<fileNamePattern>${user.dir}/logs/error/logback-demo.%d.error</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="consoleLog"/>
<appender-ref ref="fileLog"/>
<appender-ref ref="fileErrorLog"/>
</root>
</configuration>

+ 16
- 0
spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java View File

@@ -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() {
}

}

+ 43
- 0
spring-boot-demo-mybatis/pom.xml View File

@@ -0,0 +1,43 @@
<?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>

<artifactId>spring-boot-demo-mybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-demo-mybatis</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../spring-boot-demo-parent/pom.xml</relativePath>
</parent>

<properties>
<mybatis.starter.version>1.3.1</mybatis.starter.version>
<druid.starter.version>1.1.5</druid.starter.version>
</properties>

<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.starter.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.starter.version}</version>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-demo-mybatis</finalName>
</build>


</project>

+ 12
- 0
spring-boot-demo-mybatis/src/main/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplication.java View File

@@ -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);
}
}

+ 48
- 0
spring-boot-demo-mybatis/src/main/resources/application.yml View File

@@ -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

+ 19
- 0
spring-boot-demo-mybatis/src/main/resources/init-sql/schema.sql View File

@@ -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');

+ 16
- 0
spring-boot-demo-mybatis/src/test/java/com/xkcoding/springbootdemomybatis/SpringBootDemoMybatisApplicationTests.java View File

@@ -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() {
}

}

+ 76
- 0
spring-boot-demo-parent/pom.xml View File

@@ -0,0 +1,76 @@
<?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>com.xkcoding</groupId>
<artifactId>spring-boot-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>spring-boot-demo-parent</name>
<description>Demo project for Spring Boot</description>

<modules>
<module>../spring-boot-demo-helloworld</module>
<module>../spring-boot-demo-logback</module>
<module>../spring-boot-demo-mybatis</module>
</modules>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.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.8</java.version>
</properties>

<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>

<!--DB-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--工具类-->
<dependency>
<groupId>com.xiaoleilu</groupId>
<artifactId>hutool-all</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

Loading…
Cancel
Save