스프링 부트에서 Postgre를 사용하여 Data Source를 로드할 수 없음SQL 드라이버
Spring Boot 1.0.2를 사용한 시제품 개발에 성공했습니다.릴리즈 (1.0.1이었습니다).오늘까지 공개).
다음과 같은 솔루션을 검색 및 검색하여 시도했습니다.스탠드 아론 Tomcat Spring Boot / Spring Data import.sql은 Spring-Boot-1.0.0을 실행하지 않습니다.RC1
그들은 모두 스프링 부츠에게 일을 맡길 것을 제안한다.H2를 사용하면 모든 것이 작동하지만 Postgre로 전환하려고 하면SQL, 이해했습니다.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined
build.gradle은 다음과 같습니다.
loadConfiguration()
def loadConfiguration() {
def environment = hasProperty('env') ? env : 'dev'
project.ext.envrionment = environment
println "Environment is set to $environment"
def configFile = file('config.groovy')
def config = new ConfigSlurper("$environment").parse(configFile.toURL())
project.ext.config = config
}
buildscript {
ext {
springBootVersion = '1.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'groovy'
war {
baseName = 'test'
version = '0.0.1-SNAPSHOT'
}
configurations {
providedRuntime
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
compile("postgresql:postgresql:9.1-901.jdbc4")
//compile("com.h2database:h2")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
application.properties:
spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/cms
spring.datasource.username=cms
spring.datasource.password=NA
application.properties를 삭제하고 의존관계를 H2로 되돌리면 모든 것이 정상입니다.
어디가 잘못되었는지 알 수 없다:-
이것은 어디에서 온 것입니까?database.driverClassName=org.postgresql.Driver그 말은?spring.datasource.driverClassName?
spring.datasource.driver-class-name=org.postgresql.Driver
최근에 종속성에 포스트그림을 추가한 경우 프로젝트를 다시 로드하십시오.
의존관계가 갱신되지 않은 경우 mvn 프로젝트를 다시 Import해 보십시오.또, 다음의 조작도 추가해 주세요.pom.xml
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
또는 고객님께build.gradle
implementation "postgresql:postgresql:9.1-901.jdbc4"
비슷한 문제가 있어서 pom.xml을 체크해야 했고 H2 dep을 그대로 두었습니다.
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
날 위해 고친 것 같아.
이건 내 안에 있어build.gradle:
실장 'http.postgresql:postgresql:version-number'
하지만 내가 뭘 했든 그 항아리는 다운로드 되지 않았어
회피책으로 여기서 항아리를 다운로드했습니다(클릭).Jar(...)를 사용하여 수동으로 Java Build Path - Libraries이상적이진 않지만, 2분 안에 되는 건 그것뿐이에요!
방금 이 스레드를 사용했는데 도움이 되지 않았습니다.이 문제는 잘못된 설정 pom.xml에서도 발생했기 때문에 JPA를 추가해야 했습니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
도움이 되길 바랍니다!
프로젝트가 Java 17과 gradle 7.5로 이행했을 때 이 문제가 발생하였습니다.
이 문제를 해결하기 위해 다음 단계를 따릅니다.
gradle Import가 다음으로 업그레이드되었습니다.implementation 'org.postgresql:postgresql:42.2.27'
프로젝트를 클린 빌드합니다../gradlew clean build그리고나서./gradlew bootRun
문제를 해결했습니다.
언급URL : https://stackoverflow.com/questions/23287462/spring-boot-fails-to-load-datasource-using-postgresql-driver
'codememo' 카테고리의 다른 글
| 카트 항목 이름, 수량 모든 세부 정보 가져오기 (0) | 2023.02.12 |
|---|---|
| mongodb python 연결을 닫는 방법 (0) | 2023.02.12 |
| outside/esc 클릭 시 Angularjs 부트스트랩모달 종료 콜 (0) | 2023.02.08 |
| 각도 js에 ng-include 로드 완료 (0) | 2023.02.08 |
| Woocommerce 3에서 제품 속성 레이블 이름을 가져옵니다. (0) | 2023.02.08 |