@@ -0,0 +1,4 @@ | |||||
.idea/ | |||||
*.iml | |||||
logs/ | |||||
target/ |
@@ -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> |
@@ -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; | |||||
} | |||||
} |
@@ -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 |
@@ -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() { | |||||
} | |||||
} |
@@ -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> |
@@ -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); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,6 @@ | |||||
server: | |||||
port: 8080 | |||||
context-path: /demo | |||||
spring: | |||||
application: | |||||
name: logback-demo |
@@ -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> |
@@ -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() { | |||||
} | |||||
} |
@@ -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> |
@@ -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); | |||||
} | |||||
} |
@@ -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 |
@@ -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'); |
@@ -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() { | |||||
} | |||||
} |
@@ -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> |