programing

데이터 소스를 자동 구성하지 못했습니다. 'spring.datasource.url'이 지정되지 않았습니다.

kingscode 2023. 4. 1. 14:18
반응형

데이터 소스를 자동 구성하지 못했습니다. 'spring.datasource.url'이 지정되지 않았습니다.

웹, MongoDB, JPA 의존관계를 가진 SPRING INITIALIZR에서 기본적인 스프링 부트 어플리케이션을 만들었습니다.

스프링 부트 애플리케이션을 실행하려고 하면 다음과 같은 예외가 발생합니다.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-03-25 16:27:02.807 ERROR 16256 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class

Action:

Consider the following situation:
If you want an embedded database like H2, HSQL or Derby, please add it in the Classpath.
If you have database settings to be loaded from a particular profile you may need to activate it since no profiles were currently active.

application.properties 파일에는 다음과 같은 설정이 있습니다.

server.port=8081
spring.data.mongodb.database=TestDatabase
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017

사용하는 버전: Spring: 5.0.4, MongoDB: 3.6, Spring Boot: 2.0

pom.xml 파일에 mongodb와 data-jpa의 의존관계를 모두 추가했기 때문에 다음과 같은 의존관계 경합이 발생하고 있습니다.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

jpa 종속성을 제거하고 실행해 보십시오.잘 될 거예요.

application.properties가 있는 Resources 폴더로 이동하여 해당 폴더에서 다음 코드를 업데이트합니다.

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

리소스 폴더의 application.properties 파일에 다음 행을 추가하고 응용 프로그램을 재시작합니다.

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

이 에러가 발생한 것은 단지, 이 에러의 철자를 잘못 입력했기 때문입니다.spring.datasource.urlpostgresql을 사용하고 있었습니다.

문제는 다음과 같습니다. jdbc:postgres://localhost:<port-number>/<database-name>

고정처: jdbc:postgresql://localhost:<port-number>/<database-name>

주의: 차이는 다음과 같습니다.postgres&postgresql, 두 가지는 다른 두 가지입니다.

자세한 원인과 해결 방법은 여기를 참조하십시오.

MongoDB 드라이버가 없는 것 같습니다.다음과 같은 의존관계를 포함하다pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

데이터를 기반으로 한 의존관계는 생성되지 않은 각각의 엔티티를 찾으려 하고, 데이터를 기반으로 의존관계를 코멘트하고 앱을 다시 실행합니다.

<!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-data-jpa</artifactId> -->
        <!-- </dependency> -->

이 에러는 maven 또는 gradle과 같이 스프링 부트컨피규레이션파일에 JPA 의존관계를 삽입할 때 발생합니다.솔루션은 다음과 같습니다.Spring-Boot

application.properties 파일에서 DB 연결 문자열과 드라이버 세부 정보를 지정해야 합니다.이것으로 문제가 해결됩니다.이게 누군가에게 도움이 될지도 몰라.

i프로젝트가 IDE/STS(스프링 툴 슈트)로 실행되었을 때 "project.jar"가
생성되었을 때 이 문제에
직면한 사람
이 있는지 확인합니다.

탈출구는 다음과 같습니다.

application.yml 파일의 불필요한 공백 "이 원인일 수 있습니다.

server:
  port: 8085


spring:
 datasource:
  url: jdbc:mysql://localhost:3306/studentdb
  username: root
  password: root
  driver-class-name: com.mysql.cj.jdbc.Driver
 jpa:
   hibernate:
    ddl-auto: update
   show-sql: true
   database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
 application:
  name: STUDENT-SERVICE

"application.yml" 파일을 수정하는 대신
application.yml 파일에 있는 모든 스테이트먼트를 로 이동했을 뿐입니다.
"application.properties" 파일을 만들고 ".properties"에 필요한 문 형식을 지정합니다.

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/studentdb
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format.sql=true

spring.application.name=student-service

server.port=8085

및 voila

mongodb, web, jpa와 같은 종속성을 추가합니다.나머지 부분을 삭제/삭제합니다.

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

gradle build i는 다음과 같습니다.

compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-devtools')

제거된

**`compile('org.springframework.boot:spring-boot-starter-data-jpa')`**

나한테는 효과가 있었어요

@Bhabadyuti Bal은 우리에게 좋은 답변을 준다.그래들에서는 다음과 같이 사용할 수 있다.

compile 'org.springframework.boot:spring-boot-starter-data-jpa' 
compile 'com.h2database:h2'

테스트 시간:

testCompile 'org.reactivecommons.utils:object-mapper:0.1.0'
testCompile 'com.h2database:h2'

org.delective 의존관계를 추가함으로써 문제가 해결되었습니다.

<dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <scope>runtime</scope>
        </dependency>

application.properties에 jdbc URL을 잘못 입력했을 때 이 문제가 발생했습니다.이것이 누군가에게 도움이 되기를 바랍니다: 전:

spring.datasource.url=jdbc://localhost:3306/test

그 후:

spring.datasource.url=jdbc:mysql://localhost:3306/test

언급URL : https://stackoverflow.com/questions/49475177/failed-to-auto-configure-a-datasource-spring-datasource-url-is-not-specified

반응형