Skip to content

Commit 502935f

Browse files
JeffLi1993liqiangqiang
authored and
liqiangqiang
committed
属性
1 parent f32f86c commit 502935f

File tree

7 files changed

+259
-37
lines changed

7 files changed

+259
-37
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE" level="project" />
15+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.5.1.RELEASE" level="project" />
16+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.5.1.RELEASE" level="project" />
17+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.5.1.RELEASE" level="project" />
18+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.9" level="project" />
19+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.9" level="project" />
20+
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.22" level="project" />
21+
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.22" level="project" />
22+
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.22" level="project" />
23+
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
24+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.1.RELEASE" level="project" />
25+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.11" level="project" />
26+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.11" level="project" />
27+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.11" level="project" />
28+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.3.4.Final" level="project" />
29+
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
30+
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
31+
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" />
32+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
33+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
34+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
35+
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.6.RELEASE" level="project" />
36+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.6.RELEASE" level="project" />
37+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.6.RELEASE" level="project" />
38+
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" />
39+
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.6.RELEASE" level="project" />
40+
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.6.RELEASE" level="project" />
41+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.5.1.RELEASE" level="project" />
42+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:1.5.1.RELEASE" level="project" />
43+
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.2.0" level="project" />
44+
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.2.1" level="project" />
45+
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.1" level="project" />
46+
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.3" level="project" />
47+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.22" level="project" />
48+
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:2.6.0" level="project" />
49+
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.10.19" level="project" />
50+
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.1" level="project" />
51+
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
52+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
53+
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.4.0" level="project" />
54+
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
55+
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.6.RELEASE" level="project" />
56+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.3.6.RELEASE" level="project" />
57+
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
58+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:1.4.2.RELEASE" level="project" />
59+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.5.1.RELEASE" level="project" />
60+
</component>
61+
</module>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.spring.springboot.domain;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
/**
7+
* 用户
8+
*
9+
* Created by bysocket on 18/04/2017.
10+
*/
11+
@Component
12+
@ConfigurationProperties(prefix = "user")
13+
public class User {
14+
15+
/**
16+
* 用户 ID
17+
*/
18+
private Long id;
19+
20+
/**
21+
* 年龄
22+
*/
23+
private int age;
24+
25+
/**
26+
* 用户名称
27+
*/
28+
private String desc;
29+
30+
/**
31+
* 用户 UUID
32+
*/
33+
private String uuid;
34+
35+
public Long getId() {
36+
return id;
37+
}
38+
39+
public void setId(Long id) {
40+
this.id = id;
41+
}
42+
43+
public int getAge() {
44+
return age;
45+
}
46+
47+
public void setAge(int age) {
48+
this.age = age;
49+
}
50+
51+
public String getDesc() {
52+
return desc;
53+
}
54+
55+
public void setDesc(String desc) {
56+
this.desc = desc;
57+
}
58+
59+
public String getUuid() {
60+
return uuid;
61+
}
62+
63+
public void setUuid(String uuid) {
64+
this.uuid = uuid;
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "User{" +
70+
"id=" + id +
71+
", age=" + age +
72+
", desc=" + desc +
73+
", uuid='" + uuid + '\'' +
74+
'}';
75+
}
76+
}

springboot-properties/src/main/java/org/spring/springboot/property/HomeProperties.java renamed to springboot-properties/src/main/java/org/spring/springboot/property/HomeProperties1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Created by bysocket on 17/04/2017.
1010
*/
1111
@Component
12-
public class HomeProperties {
12+
public class HomeProperties1 {
1313

1414
/**
1515
* 省份
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.spring.springboot.property;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* 家乡属性
9+
*
10+
* Created by bysocket on 17/04/2017.
11+
*/
12+
@Component
13+
@ConfigurationProperties(prefix = "home")
14+
public class HomeProperties2 {
15+
16+
/**
17+
* 省份
18+
*/
19+
private String province;
20+
21+
/**
22+
* 城市
23+
*/
24+
private String city;
25+
26+
/**
27+
* 描述
28+
*/
29+
private String desc;
30+
31+
public String getProvince() {
32+
return province;
33+
}
34+
35+
public void setProvince(String province) {
36+
this.province = province;
37+
}
38+
39+
public String getCity() {
40+
return city;
41+
}
42+
43+
public void setCity(String city) {
44+
this.city = city;
45+
}
46+
47+
public String getDesc() {
48+
return desc;
49+
}
50+
51+
public void setDesc(String desc) {
52+
this.desc = desc;
53+
}
54+
}

springboot-properties/src/main/resources/application.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ home:
33
province: 浙江省
44
city: 温岭松门
55
desc: 我家住在${home.province}的${home.city}
6+
7+
## 随机属性
8+
user:
9+
id: ${random.long}
10+
age: ${random.int[1,200]}
11+
desc: 泥瓦匠叫做${random.value}
12+
uuid: ${random.uuid}

springboot-properties/src/test/java/org/spring/springboot/property/HomePropertiesTest.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.spring.springboot.property;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
import org.spring.springboot.domain.User;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
13+
/**
14+
* 自定义配置文件测试类
15+
* <p>
16+
* Created by bysocket on 17/04/2017.
17+
*/
18+
@RunWith(SpringRunner.class)
19+
@SpringBootTest
20+
public class PropertiesTest {
21+
22+
private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesTest.class);
23+
24+
@Autowired
25+
private HomeProperties1 homeProperties1;
26+
27+
@Autowired
28+
private HomeProperties2 homeProperties2;
29+
30+
@Autowired
31+
private User user;
32+
33+
@Test
34+
public void getHomeProperties1() {
35+
LOGGER.info(homeProperties1.getProvince());
36+
Assert.assertEquals("浙江省", homeProperties1.getProvince());
37+
38+
LOGGER.info(homeProperties1.getCity());
39+
Assert.assertEquals("温岭松门", homeProperties1.getCity());
40+
41+
LOGGER.info(homeProperties1.getDesc());
42+
}
43+
44+
@Test
45+
public void getHomeProperties2() {
46+
LOGGER.info(homeProperties2.getProvince());
47+
Assert.assertEquals("浙江省", homeProperties2.getProvince());
48+
49+
LOGGER.info(homeProperties2.getCity());
50+
Assert.assertEquals("温岭松门", homeProperties2.getCity());
51+
52+
LOGGER.info(homeProperties2.getDesc());
53+
}
54+
55+
@Test
56+
public void randomTestUser() {
57+
LOGGER.info(user.toString());
58+
}
59+
60+
}

0 commit comments

Comments
 (0)