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"+
"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();}}}"#this is comment\n"+
Spring读取数据库里面的application.perproties格式的String
最新推荐文章于 2023-11-22 18:02:50 发布