Java Spring引导连接与现有JDBC连接

Java Spring引导连接与现有JDBC连接,java,spring,spring-boot,database-connection,Java,Spring,Spring Boot,Database Connection,Spring boot根据application.properties中的配置提供了自己的数据库连接。但是这里我有一个服务,它为我提供了javax.sql.Connection类型的对象 src/main/resources/application.properties server.port=9090 spring.jpa.database=POSTGRESQL spring.datasource.platform=postgres spring.datasource.url=jdbc:pos

Spring boot根据application.properties中的配置提供了自己的数据库连接。但是这里我有一个服务,它为我提供了javax.sql.Connection类型的对象

src/main/resources/application.properties

server.port=9090
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
下面是存储库的代码

package com.example.springbootdemo.repositories;
import org.springframework.data.repository.CrudRepository;
import com.example.springbootdemo.model.Box;
public interface BoxRepository extends CrudRepository<Box, Long> {
}
在这里,当我调用JPA repository的save函数时,它使用db对象保存对象,而db对象是使用它自己的一些包装器计算的


但是我必须使用一个jar,它给了我数据库连接。我必须使用从这个jar返回的连接对象,而不是src/main/resources/application.properties中的配置。现在,我需要覆盖spring boot在内部使用的连接对象。我不知道如何才能做到这一点

您有以下路径:src//main//resoruces//application.properties

server.port=9090
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

这里您需要配置

只需阅读Spring Boot手册。@Zorglube我试图通过阅读手册来解决这个问题,如何设置连接只有我能在那里找到,但如何使用现有连接?请参考此以明确方法:。在配置文件中,您必须参考JNDI提供的连接,而不是创建连接。如果您提到要配置的属性,这将非常有帮助。我已更新了我的问题,我可以使用src//main//resoruces//application.properties来实现这一点,但我希望使用现有的JDBC连接,而不是创建新的连接。在配置文件中,您必须引用JNDI提供的连接,而不是创建连接。