尝试使用jdbc作为Server将SpringBoot应用程序部署到WebSphere 9。我需要从websphere设置(而不是从app.properties)获取jdbc用户名和密码。
据我所知,我可以使用InitialConfig.lookup()或JndiDataSourceLookup,但是如何找到数据库、用户名和密码呢?
发布于 2019-12-11 20:32:35
选项1:
将以下属性添加到application.properties中
spring.datasource.jndi-name=jdbc/jndiName在spring引导主类或配置类中添加数据源bean定义
@Autowired
private Environment env;
@Bean
public DataSource dataSource() throws NamingException {
return (DataSource) new JndiTemplate()
.lookup(env.getProperty("spring.datasource.jndi-name"));
}备选方案2:
使用Java标准API
DataSource ds = javax.naming.InitialContext.doLookup("jdbc/jndiName");https://stackoverflow.com/questions/59292973
复制相似问题