Spring boot与现有的JDBC连接连接

问题描述 投票:-2回答:1

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> {
}

控制器代码

package com.example.springbootdemo.controllers;

import com.example.springbootdemo.model.Box;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.springbootdemo.repositories.BoxRepository;

@RestController
public class BoxController {

@Autowired
BoxRepository boxrepository;

@PostMapping("/box")
public Box addBox(Box box){
    return this.boxrepository.save(box);
}
}

在这里,当我调用JPA信息库的保存功能时,它使用它自己的一些包装程序正在计算的db对象保存对象。

但是我必须使用一个提供数据库连接的jar。代替在src / main / resources / application.properties中进行配置,我必须使用从此jar返回的连接对象。现在,我需要覆盖spring boot内部使用的连接对象。我无法弄清楚该如何做。

java spring spring-boot database-connection
1个回答
1
投票

您具有此路径:src // main // resoruces // application.properties

并且在这里您需要配置

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