【问题标题】:Spring boot application need to connect weblogic oracle datasourcespring boot应用需要连接weblogic oracle数据源
【发布时间】:2017-11-24 18:04:22
【问题描述】:

Spring Boot 应用程序默认连接到 derby 嵌入式数据库,如下面的语句所示。

启动嵌入式数据库:url='jdbc:derby:memory:testdb;create=true', username='sa'

我不知道上面的网址是从哪里挑出来的

我需要连接 weblogic oracle 数据源我在应用程序的 application.properties 中提供了以下属性,但它没有选择以下属性

spring.jpa.hibernate.ddl-auto=create-drop

# Oracle settings
spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/XE
spring.datasource.username=system
spring.datasource.password=vasu
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

在 pom.xml 中添加了以下条目

<dependency>
    <groupId>com.github.noraui</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.2</version>
</dependency>   

【问题讨论】:

  • 我是com.github.noraui的共同创建者,这个jar文件已被弃用,请使用这个示例:github.com/sgrillon14/MavenSampleOracleJdbc

标签: oracle spring-boot spring-data-jpa


【解决方案1】:

我假设您已经在 weblogic 中定义了 oracle 数据源,因此您不需要在应用程序类路径中定义 oracle 驱动程序,也不需要定义 spring.datasource.{url,username,password,driver-class-name} 属性。

您需要的是 spring.datasource.jndi-name 属性。只需将它设置为来自 weblogic 的数据源的 jndi 名称,spring 就会像这样获取它。

当然,你必须在 weblogic 类路径(lib 目录或类似目录)中有一个 oracle 驱动程序。

spring.datasource.jndi-name=java:jdbc/OracleDS

Documentation.

【讨论】:

  • 嗨。如果 webapp 不在 localhost 中,你知道我该怎么办吗?像这样:“spring.datasource.jndi-name: t3//192.151.110.180:7001/jdbc/conEsos”
  • @J.Abel 你能找到问题的答案吗?
  • 是的,我可以得到它,但是我不能从 application.config 文件中得到它。我是从 @Configuration 类做的。
  • @J.Abel 我也在尝试解决这个问题,但还没有找到解决方案。你能给我一些提示吗?
猜你喜欢
  • 2020-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-10
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多