如何连接Spring和Oracle db (oracle cloud) 19c
How to connect Spring and Oracle db (oracle cloud) 19c
如果我尝试连接这个错误显示
oracle.net.ns.NetException: 连接字符串格式无效,有效格式为:"host:port:sid" (CONNECTION_ID=plSfz1GBTiKKWbZqZbjUrA==)
我认为 yml 数据源或 jpa 是错误的...
但我在任何地方都检查了护目镜,但是,
oracle cloud(wallet) <-> spring 是我找不到它
请帮助我!
这是我的build.gradle
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
}
group = ''
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'junit:junit:4.13.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
implementation 'com.oracle.ojdbc:ucp'
implementation 'com.oracle.database.security:oraclepki'
implementation 'com.oracle.database.security:osdt_core'
implementation 'com.oracle.database.security:osdt_cert'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
这是我的application.yml
# local, dev, prod 공통 설정
server:
port: 8080
tomcat:
uri-encoding: UTF-8
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@[TNSNAME]?TNS_ADMIN=./src/main/resources/Wallet
username:
password:
jpa:
database-platform: org.hibernate.dialect.Oracle12cDialect
open-in-view: true
hibernate:
ddl-auto: none
# ddl-auto: create-drop
# ddl-auto: validate
如果您使用 TNS_ADMIN,它必须是 TNS_ADMIN 文件的路径,并且您的连接必须在 tnsnames.ora
.
中声明
请参阅此 blog 以获取代码示例和说明。
我是这样解决的,
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@<***TLSNAME>?TNS_ADMIN=D:/Wallet
username: username
password: password
如果我尝试连接这个错误显示 oracle.net.ns.NetException: 连接字符串格式无效,有效格式为:"host:port:sid" (CONNECTION_ID=plSfz1GBTiKKWbZqZbjUrA==)
我认为 yml 数据源或 jpa 是错误的... 但我在任何地方都检查了护目镜,但是, oracle cloud(wallet) <-> spring 是我找不到它 请帮助我!
这是我的build.gradle
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
}
group = ''
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'junit:junit:4.13.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
implementation 'com.oracle.ojdbc:ucp'
implementation 'com.oracle.database.security:oraclepki'
implementation 'com.oracle.database.security:osdt_core'
implementation 'com.oracle.database.security:osdt_cert'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
这是我的application.yml
# local, dev, prod 공통 설정
server:
port: 8080
tomcat:
uri-encoding: UTF-8
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@[TNSNAME]?TNS_ADMIN=./src/main/resources/Wallet
username:
password:
jpa:
database-platform: org.hibernate.dialect.Oracle12cDialect
open-in-view: true
hibernate:
ddl-auto: none
# ddl-auto: create-drop
# ddl-auto: validate
如果您使用 TNS_ADMIN,它必须是 TNS_ADMIN 文件的路径,并且您的连接必须在 tnsnames.ora
.
请参阅此 blog 以获取代码示例和说明。
我是这样解决的,
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@<***TLSNAME>?TNS_ADMIN=D:/Wallet
username: username
password: password