配置文件详解:自定义属性、随机数、多环境配置等

This commit is contained in:
程序猿DD
2016-05-05 14:00:16 +08:00
parent 75e8833e84
commit fa5b08a6ab
9 changed files with 265 additions and 0 deletions
@@ -0,0 +1,48 @@
package com.didispace;
import com.didispace.service.BlogProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author 程序猿DD
* @version 1.0.0
* @blog http://blog.didispace.com
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
public class ApplicationTests {
private static final Log log = LogFactory.getLog(ApplicationTests.class);
@Autowired
private BlogProperties blogProperties;
@Test
public void getHello() throws Exception {
Assert.assertEquals(blogProperties.getName(), "程序猿DD");
Assert.assertEquals(blogProperties.getTitle(), "Spring Boot教程");
Assert.assertEquals(blogProperties.getDesc(), "程序猿DD正在努力写《Spring Boot教程》");
log.info("随机数测试输出:");
log.info("随机字符串 : " + blogProperties.getValue());
log.info("随机int : " + blogProperties.getNumber());
log.info("随机long : " + blogProperties.getBignumber());
log.info("随机10以下 : " + blogProperties.getTest1());
log.info("随机10-20 : " + blogProperties.getTest2());
}
}