[英]How to get JNDI datasource in Spring Boot from IBM WebSphere 9
Trying to deploy SpringBoot app to WebSphere 9 with using jdbc as SQL Server.尝试使用 jdbc 作为 SQL Server 将 SpringBoot 应用程序部署到 WebSphere 9。 I need to get jdbc username and password from websphere settings (not from app.properties).
我需要从 websphere 设置(而不是从 app.properties)获取 jdbc 用户名和密码。
As I understand, I can use InitialConfig.lookup() or JndiDataSourceLookup, but how could I find database, username and password?据我了解,我可以使用 InitialConfig.lookup() 或 JndiDataSourceLookup,但是我怎么能找到数据库、用户名和密码呢?
Option 1:选项1:
Add the following property into application.properties
将以下属性添加到
application.properties
spring.datasource.jndi-name=jdbc/jndiName
add datasource bean definition in spring boot main class or config class在 spring boot 主类或配置类中添加数据源 bean 定义
@Autowired
private Environment env;
@Bean
public DataSource dataSource() throws NamingException {
return (DataSource) new JndiTemplate()
.lookup(env.getProperty("spring.datasource.jndi-name"));
}
Option 2:选项 2:
using Java standard API使用 Java 标准 API
DataSource ds = javax.naming.InitialContext.doLookup("jdbc/jndiName");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.