使用oracle数据库运行spring boot服务时出错

问题描述 投票:0回答:1

当我尝试在本地运行 spring boot 服务(用于查询数据库表)时,它给了我错误。 该服务尝试连接到 oracle 数据库。

下面是我们看到的错误 无法打开 JPA EntityManager 进行事务 无法获取 JDBC 连接 [IO 错误:网络适配器无法建立连接 (CONNECTION_ID=IEChbPx1QbKHU7IgPuOdrQ==)] [不适用] 网络适配器无法建立连接 (CONNECTION_ID=IEChbPx1QbKHU7IgPuOdrQ==) 连接被拒绝:连接,套接字连接失效 1 毫秒。本地主机 1522 0 (2/2) 真 连接被拒绝:连接

pom 文件。

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc11</artifactId>
            <scope>runtime</scope>
        </dependency>       
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ucp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

应用程序属性文件

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR

server.port=2024
server.servlet.context-path= --removed

spring.datasource.url=jdbc:oracle:thin:@//localhost:1522/--removed servicename
spring.datasource.username=
spring.datasource.password=

spring.datasource.type=oracle.jdbc.pool.OracleDataSource
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.database=oracle
spring.application.name=LITGEMService

应用程序主文件

package com.LITIntegration.main;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
public class LitApplication implements CommandLineRunner  {

    @Autowired
    private LitLirRepository litLirRepo;        
    public static void main(String[] args) {
        SpringApplication.run(LitApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // TODO Auto-generated method stub
        List<LitLirEntity> lirview = litLirRepo.findAll();
        lirview.forEach(System.out :: println);
    }

}

实体类

package com.LITIntegration.main;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "removed")
public class LitLirEntity {
    @Id
    @Column(name = "LICENSE_INVENTORY_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
 
    private String REVIEW_ID;
    private String NOTES;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getREVIEW_ID() {
        return REVIEW_ID;
    }
    public void setREVIEW_ID(String rEVIEW_ID) {
        REVIEW_ID = rEVIEW_ID;
    }
    public String getNOTES() {
        return NOTES;
    }
    public void setNOTES(String nOTES) {
        NOTES = nOTES;
    }
    @Override
    public String toString() {
        return "LitLirEntity [id=" + id + ", REVIEW_ID=" + REVIEW_ID + ", NOTES=" + NOTES + "]";
    }
}

存储库

package com.LITIntegration.main;

import org.springframework.data.jpa.repository.JpaRepository;

public interface LitLirRepository extends JpaRepository<LitLirEntity, Long>{

}
oracle spring-boot jpa spring-jdbc ojdbc
1个回答
0
投票

请检查您的数据库侦听器是否在本地主机端口 1522 上运行。 您应该首先尝试使用简单的 java 测试连接到数据库。

© www.soinside.com 2019 - 2024. All rights reserved.