Spring读取数据库里面的application.perproties格式的String

xiaoxiao2021-02-28  93

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();}}}
转载请注明原文地址: https://www.6miu.com/read-50258.html

最新回复(0)