when I try to run spring boot application (used for querying Database table) locally it gives me error. The service tries to connect to oracle database. The database url,port,service name, username and password are correct which are valid when tested from sql devloper
Below is the error:
Could not open JPA EntityManager for transaction
Unable to acquire JDBC Connection [IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=IEChbPx1QbKHU7IgPuOdrQ==)] [n/a]
The Network Adapter could not establish the connection (CONNECTION_ID=IEChbPx1QbKHU7IgPuOdrQ==)
Connection refused: connect, socket connect lapse 1 ms. localhost 1522 0 (2/2) true
the pom file.
<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>
The application properties file
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
Application main file
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);
}
}
Entity Class
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 + "]";
}
}
Repository
package com.LITIntegration.main;
import org.springframework.data.jpa.repository.JpaRepository;
public interface LitLirRepository extends JpaRepository<LitLirEntity, Long>{
}
Please check if your database listener is running at local host port 1522 or not. You should first try connecting to DB using a simple java test.