Skip to content

Commit

Permalink
Spring Boot 基础配置
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 4, 2017
1 parent 9e2e132 commit 34ab48d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
31 changes: 31 additions & 0 deletions library-sboot/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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">
<parent>
<artifactId>library</artifactId>
<groupId>com.mine</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>library-sboot</artifactId>
<properties>
<spring-boot-starter-version>1.5.2.RELEASE</spring-boot-starter-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-starter-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
55 changes: 55 additions & 0 deletions library-sboot/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 实战 Spring Boot
>
## Spring Boot 基础
### Spring Boot概述
#### 什么是Spring Boot
>随着动态语言的流行(Ruby、Groovy、Scala、Node.js),Java的开发显得格外的笨重:繁多的配置、低下的开发效率、复杂的部署流程以及
第三方技术集成难度大。

## Spring Boot 核心
### 基本配置
#### 入口类和@SpringBootApplication
#### 关闭特定的自动配置
#### 定制 Banner
修改 Banner
- 在Spring Boot启动的时候会有一个默认启动图标。
- 我们在src/main/resources 下新建一个banner.txt。
- 通过http://patorjk.com/software/taag网站生成字符,如敲入的为“WISELY”,将网站生成的字符复制到banner.txt中。
- 这时再启动程序,图案就会变为网站生成的图案。

关闭 Banner
- main里的内容修改为
```java
@RestController
@SpringBootApplication //Spring Boot项目的核心注解,主要目的是开启自动配置
public class LibraryApplication {
@RequestMapping("/")
String index() {
return "Hello Spring Boot !";
}

public static void main(String[] args) {
// SpringApplication.run(LibraryApplication.class, args);
SpringApplication application = new SpringApplication(LibraryApplication.class);
application.setBannerMode(Banner.Mode.OFF); // 关闭 banner
application.run(args);
}
}
```
#### Spring Boot的配置文件
>Spring Boot使用一个全局的配置文件application.properties或application.yml,放置在src/main/resources目录或者类路径的/config
下。

Spring Boot不仅支持常规的properties配置文件,还支持yaml语言的配置文件。yaml是以数据为中心的语言,在配置数据的时候具有面向对象
的特性。

Spring Boot的全局配置文件的作用是对一些默认配置的配置值进行修改。

简单示例

将Tomcat的默认端口8080修改为8800,并将默认的访问路径“/”改为“/sboot”。可以在application.properties中添加:
```properties
server.port=8800
server.context-path=/sboot
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mine.library.sboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Created by liuff on 2017/4/4.
*/
@RestController
@SpringBootApplication //Spring Boot项目的核心注解,主要目的是开启自动配置
public class LibraryApplication {
@RequestMapping("/")
String index() {
return "Hello Spring Boot !";
}

public static void main(String[] args) {
// SpringApplication.run(LibraryApplication.class, args);
SpringApplication application = new SpringApplication(LibraryApplication.class);
// application.setBannerMode(Banner.Mode.OFF); // 关闭 banner
application.run(args);
}
}
2 changes: 2 additions & 0 deletions library-sboot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.port=8800
server.context-path=/sboot
7 changes: 7 additions & 0 deletions library-sboot/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
██╗ ██╗██████╗ ██████╗ █████╗ ██████╗ ██╗ ██╗ ███████╗██████╗ ██████╗ ██████╗ ████████╗
██║ ██║██╔══██╗██╔══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔════╝██╔══██╗██╔═══██╗██╔═══██╗╚══██╔══╝
██║ ██║██████╔╝██████╔╝███████║██████╔╝ ╚████╔╝█████╗███████╗██████╔╝██║ ██║██║ ██║ ██║
██║ ██║██╔══██╗██╔══██╗██╔══██║██╔══██╗ ╚██╔╝ ╚════╝╚════██║██╔══██╗██║ ██║██║ ██║ ██║
███████╗██║██████╔╝██║ ██║██║ ██║██║ ██║ ██║ ███████║██████╔╝╚██████╔╝╚██████╔╝ ██║
╚══════╝╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝ ╚═════╝ ╚═╝

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modules>
<module>library-utils</module>
<module>library-spring</module>
<module>library-sboot</module>
</modules>
<packaging>pom</packaging>

Expand Down

0 comments on commit 34ab48d

Please sign in to comment.