简体   繁体   English

春季启动:Oracle RAC DB连接配置

[英]Spring boot: Oracle RAC DB connection configuration

In Spring boot application, Need to configure Oracle RAC DB URL. 在Spring启动应用程序中,需要配置Oracle RAC DB URL。 Can someone explain how to configure the Oracle RAC URL in application.properties? 有人可以解释如何在application.properties中配置Oracle RAC URL吗?

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL={PROTOCOL})(HOST={{URL})(PORT={PORT})))(CONNECT_DATA=(SERVICE_NAME={SERVICE_NAME})))

Have verified the Spring boot official doc and didn't find anything related. 已验证Spring Boot官方文档,但未找到任何相关内容。 Even verified in the Common Properties and can't find any references. 即使在通用属性中进行了验证,也找不到任何引用。

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

Thanks for your help in advance! 谢谢您的帮助!

Try with below. 请尝试以下。

jdbc:oracle:thin:@(DESCRIPTION=
    @    (LOAD_BALANCE=on)
    @    (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
    @    (ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521))
    @    (CONNECT_DATA=(SERVICE_NAME=service_name)))

OR 要么

# Oracle settings
spring.datasource.url=jdbc:oracle:thin:@localhost:1522:orcl
spring.datasource.username=HIBERNATE_TEST
spring.datasource.password=HIBERNATE_TEST
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver

OR 要么

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db1.myco.com)(PORT=1604))
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db2.myco.com)(PORT=1604)))
(CONNECT_DATA=(SERVICE_NAME=mydb1.myco.com)(SERVER=DEDICATED)))

Sources : 资料来源:

https://docs.oracle.com/cd/E57185_01/EPMIS/apbs01s01.html https://docs.oracle.com/cd/E57185_01/EPMIS/apbs01s01.html

https://dzone.com/articles/configuring-spring-boot-for-oracle https://dzone.com/articles/configuring-spring-boot-for-oracle

This is what i did to connect to postgres in my project and it is in production now. 这是我在项目中连接到postgres的工作,现在已经投入生产。 For Oracle it is exactly same. 对于Oracle,情况完全相同。 In fact for any other RDBMS. 实际上对于任何其他RDBMS。

Add the properties in the application.yml or the application.properties in the spring boot project. 在spring.boot项目中的application.yml或application.properties中添加属性。

The below is yml configuration. 以下是yml配置。

 spring:
  jpa:
    database: POSTGRESQL
    show-sql: false
  datasource:
    platform: postgres
    url: jdbc:postgresql://123.3.4.89.com:1234/DatabaseName
    username: user123
    password: pass123
    driver-class-name: org.postgresql.Driver
    testWhileIdle: true
    validationQuery: SELECT 1

Then add the driver in the pom or the gradle build file which build tool you are using. 然后将驱动程序添加到您正在使用的构建工具的pom或gradle构建文件中。 And the jpa jar of spring boot. 还有弹簧靴子的jpa jar。

This was entry in the build.gradle file. 这是build.gradle文件中的条目。

compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.2'

Thats it, now you can create your repositories and start pushing and fetching data in the Db. 就是这样,现在您可以创建存储库,并开始在Db中推送和获取数据。

Hope this helps, cheers !!! 希望这会有所帮助,加油!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM