SpringBoot在开发环境中直接构建DataSource
import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@Slf4j
public class StringDevUtil {
public static DataSource getDevDataSource() throws IOException {
InputStream ins = StringDevUtil.class.getResourceAsStream("/application-dev.properties");
Properties prop = new Properties();
prop.load(ins);
ins.close();
String dbClass = prop.getProperty("spring.datasource.driver-class-name");
String jdbcURL = prop.getProperty("spring.datasource.url");
String user = prop.getProperty("spring.datasource.username");
String pass = prop.getProperty("spring.datasource.password");
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName(dbClass);
ds.setUrl(jdbcURL);
ds.setUsername(user);
ds.setPassword(pass);
return ds;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。