简体   繁体   English

如何从 IBM WebSphere 9 在 Spring Boot 中获取 JNDI 数据源

[英]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.

相关问题 Spring 在 Websphere 9 上启动数据源 JNDI 查找 - Spring Boot Datasource JNDI lookup on Websphere 9 无法构建具有从jndi查找数据源的Spring Boot项目 - Unable to build Spring Boot project having datasource lookup from jndi 如何使用Spring Boot和WildFly 11.0配置JNDI数据源 - How to configure a JNDI DataSource with Spring Boot & WildFly 11.0 带有 WebSphere 9.0.0.7 的 Spring Boot 的 JNDI 配置 - JNDI configuration with spring boot with WebSphere 9.0.0.7 使用 JNDI 在 Spring Boot 中配置多个数据源 - Configure Multiple DataSource in Spring Boot with JNDI Spring Boot:如何禁用 JNDI 查找并使用 spring.datasource 代替测试? - Spring Boot: How to Disable JNDI lookup and use spring.datasource instead for Testing? 如何使用给定的JNDI名称连接到Websphere数据源? - How do I connect to a Websphere Datasource with a given JNDI name? Spring Boot - 来自 JNDI 的数据源:NoInitialContextException:需要在环境或系统属性中指定类名 - Spring Boot - DataSource from JNDI: NoInitialContextException: Need to specify class name in environment or system property 使用tomcat数据源-如何通过spring jndi访问数据源以获取当前数据库池状态 - using tomcat datasource - how to access datasource to get current db pool status by spring jndi 来自具有JNDI的其他IP服务器的spring.datasource.jndi-name - spring.datasource.jndi-name from different ip server with JNDI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM