mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-14 14:13:52 +08:00
Spring Boot 配置文件
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package org.spring.springboot.property;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 家乡属性
|
||||
*
|
||||
* Created by bysocket on 17/04/2017.
|
||||
*/
|
||||
@Component
|
||||
public class HomeProperties1 {
|
||||
|
||||
/**
|
||||
* 省份
|
||||
*/
|
||||
@Value("${home.province}")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
@Value("${home.city}")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Value("${home.desc}")
|
||||
private String desc;
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HomeProperties1{" +
|
||||
"province='" + province + '\'' +
|
||||
", city='" + city + '\'' +
|
||||
", desc='" + desc + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spring.springboot.domain.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@@ -22,39 +21,19 @@ public class PropertiesTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesTest.class);
|
||||
|
||||
@Autowired
|
||||
private HomeProperties1 homeProperties1;
|
||||
private UserProperties userProperties;
|
||||
|
||||
@Autowired
|
||||
private HomeProperties2 homeProperties2;
|
||||
|
||||
@Autowired
|
||||
private User user;
|
||||
private HomeProperties homeProperties;
|
||||
|
||||
@Test
|
||||
public void getHomeProperties1() {
|
||||
LOGGER.info(homeProperties1.getProvince());
|
||||
Assert.assertEquals("浙江省", homeProperties1.getProvince());
|
||||
|
||||
LOGGER.info(homeProperties1.getCity());
|
||||
Assert.assertEquals("温岭松门", homeProperties1.getCity());
|
||||
|
||||
LOGGER.info(homeProperties1.getDesc());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHomeProperties2() {
|
||||
LOGGER.info(homeProperties2.getProvince());
|
||||
Assert.assertEquals("浙江省", homeProperties2.getProvince());
|
||||
|
||||
LOGGER.info(homeProperties2.getCity());
|
||||
Assert.assertEquals("温岭松门", homeProperties2.getCity());
|
||||
|
||||
LOGGER.info(homeProperties2.getDesc());
|
||||
public void getHomeProperties() {
|
||||
LOGGER.info(homeProperties.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomTestUser() {
|
||||
LOGGER.info(user.toString());
|
||||
LOGGER.info(userProperties.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
springboot-properties/src/test/resouorces/application.yml
Normal file
12
springboot-properties/src/test/resouorces/application.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
## 家乡属性
|
||||
home:
|
||||
province: 浙江省
|
||||
city: 温岭松门
|
||||
desc: 我家住在${home.province}的${home.city}
|
||||
|
||||
## 随机属性
|
||||
user:
|
||||
id: ${random.long}
|
||||
age: ${random.int[1,200]}
|
||||
desc: 泥瓦匠叫做${random.value}
|
||||
uuid: ${random.uuid}
|
||||
Reference in New Issue
Block a user