新增 spring boot 整合 servlet 用例
This commit is contained in:
54
spring-boot/spring-boot-yml-profile/pom.xml
Normal file
54
spring-boot/spring-boot-yml-profile/pom.xml
Normal 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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.heibaiying</groupId>
|
||||
<artifactId>spring-boot-yml-profile</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-boot-yml-profile</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<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>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--配置文件处理器,导入后书写自定义配置时候会有提示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
package com.heibaiying.ymlprofile;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootYmlApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootYmlApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.heibaiying.ymlprofile.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
* @description : 属性配置映射类
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "programmer")
|
||||
@Data
|
||||
@ToString
|
||||
public class Programmer {
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
private boolean married;
|
||||
private Date hireDate;
|
||||
private float salary;
|
||||
private int random;
|
||||
private Map<String, String> skill;
|
||||
private List company;
|
||||
private School school;
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.heibaiying.ymlprofile.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
*/
|
||||
@Data
|
||||
public class School {
|
||||
private String name;
|
||||
private String location;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.heibaiying.ymlprofile.controller;
|
||||
|
||||
import com.heibaiying.ymlprofile.config.Programmer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("yml")
|
||||
public class YmlController {
|
||||
|
||||
@Autowired
|
||||
private Programmer programmer;
|
||||
|
||||
@RequestMapping
|
||||
public Programmer programmer(){
|
||||
return programmer;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
# 字符串默认不用加上单引号或者双引号,但是如果字符串之中包含空格或特殊字符,需要放在引号之中。
|
||||
# "":双引号;双引号不会对特殊字符转义
|
||||
# '':单引号;会进行转义
|
||||
|
||||
programmer:
|
||||
name: xiaoming-DEV
|
||||
married: false
|
||||
hireDate: 2018/12/23
|
||||
salary: 66666.88
|
||||
random: ${random.int[1024,65536]}
|
||||
skill: {java: master, jquery: proficiency}
|
||||
company: [baidu,tengxun,alibaba]
|
||||
school:
|
||||
name: unviersity
|
||||
location: shanghai
|
||||
|
||||
|
@ -0,0 +1,18 @@
|
||||
# 字符串默认不用加上单引号或者双引号,但是如果字符串之中包含空格或特殊字符,需要放在引号之中。
|
||||
# "":双引号;双引号不会对特殊字符转义
|
||||
# '':单引号;会进行转义
|
||||
|
||||
programmer:
|
||||
name: xiaoming-PROD
|
||||
age: 23
|
||||
married: false
|
||||
hireDate: 2018/12/23
|
||||
salary: 66666.88
|
||||
random: ${random.int[1024,65536]}
|
||||
skill: {java: master, jquery: proficiency}
|
||||
company: [baidu,tengxun,alibaba]
|
||||
school:
|
||||
name: unviersity
|
||||
location: shanghai
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
# ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
# <20><><EFBFBD>õIJ<C3B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD> <20><>dev<65><76>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>age,<2C><><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õģ<C3B5><C4A3><EFBFBD>prod<6F><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dev,<2C>ᰴ<EFBFBD>վ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>ȣ<EFBFBD>ʹ<EFBFBD><CAB9>dev<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>Բ鿴<D4B2><E9BFB4>Ŀ<EFBFBD><C4BF>README.md
|
||||
programmer:
|
||||
age: 999
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.heibaiying.ymlprofile;
|
||||
|
||||
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 SpringBootYmlProfileApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user