package unit.test;
import java.io.IOException;
import java.util.Properties;
import org.junit.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class StringPropertyLoadTest {
@Test
public void testLoad(){
String protertryStr =
"spring.redis.database=0\n"+
"spring.redis.host=localhost\n"+
"spring.redis.port=8080\n"+
"spring.redis.password=\n"+
"#this is comment! \n"+
"spring.redis.timeout=0\n"+
"spring.redis.pool.max-active=8 #abcd \n"+
"spring.redis.pool.max-wait=-1\n"+
"spring.redis.pool.max-idle=8\n"+
"spring.redis.pool.min-idle=0\n";
ByteArrayResource resource = new ByteArrayResource(protertryStr.getBytes(), protertryStr);
try {
Properties properties =PropertiesLoaderUtils.loadProperties(resource);
properties.entrySet().forEach(p ->{
System.out.println(p.getKey()+"="+p.getValue());
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sprint读取配置文件内容格式的String
最新推荐文章于 2022-06-28 18:11:13 发布