복붙노트

[SPRING] 데이터 소스 자동 구성에 실패했습니다 : 'spring.datasource.url'이 지정되지 않았습니다.

SPRING

데이터 소스 자동 구성에 실패했습니다 : '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

내가 사용하는 버전 : 봄 : 5.0.4, MongoDB : 3.6, 스프링 부트 : 2.0

해결법

  1. ==============================

    1.pom.xml 파일에 mongodb 및 data-jpa 종속성을 모두 추가 했으므로 아래와 같이 종속성 충돌이 발생했습니다.

    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 종속성을 제거하고 실행하십시오. 그것은 잘 작동합니다.

  2. ==============================

    2.application.properties가있는 resources 폴더로 가서 아래 코드를 업데이트하십시오.

    application.properties가있는 resources 폴더로 가서 아래 코드를 업데이트하십시오.

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

    3.application 폴더의 application.properties 파일에 아래 줄을 추가하고 응용 프로그램을 다시 시작하십시오.

    application 폴더의 application.properties 파일에 아래 줄을 추가하고 응용 프로그램을 다시 시작하십시오.

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

    4.누락 된 MongoDB 드라이버가있는 것 같습니다. pom.xml에 다음 종속성을 포함시킵니다.

    누락 된 MongoDB 드라이버가있는 것 같습니다. pom.xml에 다음 종속성을 포함시킵니다.

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

    5.데이터를 기반으로하는 의존성은 생성되지 않은 각각의 엔티티를 찾고 데이터를 기반으로하는 종속성에 대해 주석을 작성하고 앱을 다시 실행합니다.

    데이터를 기반으로하는 의존성은 생성되지 않은 각각의 엔티티를 찾고 데이터를 기반으로하는 종속성에 대해 주석을 작성하고 앱을 다시 실행합니다.

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

    6.mongodb, web, jpa와 같은 의존성을 추가하십시오. 나머지는 삭제 / 지 웁니다.

    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>
    
  7. ==============================

    7.gradle 빌드에서 간단하게 :

    gradle 빌드에서 간단하게 :

    compile ( 'org.springframework.boot : spring-boot-startter-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')`**
    

    그리고 그것은 나를 위해 일했습니다.

  8. ==============================

    8.org.apache.derby 종속성을 추가하면 내 문제가 해결되었습니다.

    org.apache.derby 종속성을 추가하면 내 문제가 해결되었습니다.

    <dependency>
                <groupId>org.apache.derby</groupId>
                <artifactId>derby</artifactId>
                <scope>runtime</scope>
            </dependency>
    
  9. from https://stackoverflow.com/questions/49475177/failed-to-auto-configure-a-datasource-spring-datasource-url-is-not-specified by cc-by-sa and MIT license