[spring] 데이터 소스를 구성하지 못했습니다. ‘url’속성이 지정되지 않았으며 포함 된 데이터 소스를 구성 할 수 없습니다.

MongoDB 로 Spring Boot Batch 예제를 작업 중이며 이미 mongod서버를 시작했습니다 .

내 응용 프로그램을 시작할 때 아래 오류가 발생합니다.

이 문제에 대한 조언이 있습니까?

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

application.properties :

# Mongo database URI. Cannot be set with host, port and credentials.
spring.data.mongodb.uri=mongodb://localhost/test 

pom.xml

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

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

mongod다음 출력으로 시작했습니다 .

C:\Users\pc>mongod
2018-07-07T14:39:39.223+0530 I JOURNAL  [initandlisten] journal dir=C:\data\db\journal
2018-07-07T14:39:39.230+0530 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2018-07-07T14:39:39.478+0530 I JOURNAL  [durability] Durability thread started
2018-07-07T14:39:39.589+0530 I CONTROL  [initandlisten] MongoDB starting : pid=11992 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-NQ639DU
2018-07-07T14:39:39.589+0530 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-07-07T14:39:39.591+0530 I CONTROL  [initandlisten] db version v3.0.5
2018-07-07T14:39:39.592+0530 I CONTROL  [initandlisten] git version: 8bc4ae20708dbb493cb09338d9e7be6698e4a3a3
2018-07-07T14:39:39.592+0530 I CONTROL  [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2018-07-07T14:39:39.592+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2018-07-07T14:39:39.593+0530 I CONTROL  [initandlisten] options: {}
2018-07-07T14:39:39.595+0530 I JOURNAL  [journal writer] Journal writer thread started
2018-07-07T14:39:40.485+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2018-07-07T14:40:39.140+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:51340 #1 (1 connection now open)
2018-07-07T14:40:41.663+0530 I NETWORK  [conn1] end connection 127.0.0.1:51340 (0 connections now open)
2018-07-07T14:45:12.421+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:51578 #2 (1 connection now open)
2018-07-07T14:45:12.870+0530 I NETWORK  [conn2] end connection 127.0.0.1:51578 (0 connections now open)
2018-07-07T14:46:21.734+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:51591 #3 (1 connection now open)
2018-07-07T14:46:22.041+0530 I NETWORK  [conn3] end connection 127.0.0.1:51591 (0 connections now open)
2018-07-07T14:57:47.523+0530 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:52534 #4 (1 connection now open)
2018-07-07T14:57:47.910+0530 I NETWORK  [conn4] end connection 127.0.0.1:52534 (0 connections now open)

여기에 이미지 설명 입력



답변

application.properties를 확인하십시오.

바꾸다

spring.datasource.driverClassName=com.mysql.jdbc.Driver

…에

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

나를 위해 일했습니다. 전체 구성 :

spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update


답변

그냥 추가 : @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
나를 위해 작동합니다.

내가 시도한 것과 같은 오류가 @EnableAutoConfiguration(exclude=...)작동하지 않았습니다.


답변

귀하의 문제는 전 이적 인 메이븐 종속성 spring-boot-starter-batch이있는 스프링 배치의 spring-boot-starter-jdbc종속성입니다.

Spring Batch는 신뢰할 수있는 내결함성 엔터프라이즈 배치 작업을 구축하기위한 프레임 워크입니다. 실패한 배치 다시 시작, 배치 실행 상태 기록 등과 같은 많은 기능을 지원합니다. Spring Batch가 등록 된 작업의 상태를 저장하기 위해 데이터베이스 스키마를 사용하도록하기 위해 자동 구성은 이미 필요한 데이터 소스의 기본 구성을 제공하며 관계형 데이터베이스 구성이 필요한 것은이 구성입니다.

이 문제를 해결하려면 같은 일부 데이터베이스 드라이버가 포함되어야합니다 mysql, h2를 구성하는 등 url.

업데이트 : 시작하기 위해 아래와 같이 application.yml을 구성 할 수 있습니다.

spring:
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:localhost;DB_CLOSE_ON_EXIT=FALSE
    username: admin
    password:

물론 다음 pom.xml과 같이 h2 드라이버를 포함하십시오.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
       ....
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

....
    </dependencies>
...

</project>

이 목적으로 mongo를 사용할 수 없기 때문에 mongo의 사용은 비즈니스 스키마가 아닌 내부 스키마 인 Spring Batch의 내부 데이터베이스를 관리하기위한 것이 아니라 항목 독자와 작성자에게만 제공되기 때문입니다. 쿼리는 일반 SQL 쿼리이며 내부 추상화는 관계형 데이터베이스에 의존합니다. 모든 배치는 작업 청크를 읽고 쓰고 작업을 다시 시작하기 위해 해당 정보를 저장하기 때문에 ACID 기능이있는 데이터베이스가 있어야합니다. NoSql 솔루션은 이에 적합하지 않습니다.

결국 내부 기능을 위해 Spring Batch를 준비하기 위해 관계형 데이터베이스를 구성했습니다. 내부 추상화는 mongo에만 jdbc에 의존하지 않습니다. 그런 다음 mongo를 사용할 수 있지만 항목 리더 / 라이터를 통해 배치의 비즈니스 측면에서 사용할 수 있습니다.

이것이 당신의 의심을 없애는 데 도움이되기를 바랍니다.


답변

질문의 요점은 아니지만 (관련 될 수 있음) 새 프로젝트를 부트 스트랩하고 왜 동일한 오류가 발생하는지 궁금하다면 종속성 섹션 의 artifactIdof spring-boot-starter-data-jpa에서 올 수 있습니다 . 아래에 의존성을 부여했습니다. 이를 제거하려면 데이터베이스를 정의해야합니다.

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


답변

DataSourceAutoConfiguration.class나를 위해 일한 제외 :

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })


답변

이 링크가 도움 되었습니다.

Spring Boot 자동 구성은 클래스 경로에 추가 된 종속성에 따라 자동으로 Bean을 구성하려고합니다. 그리고 클래스 경로에 JPA 종속성 (spring-data-starter-jpa)이 있으므로이를 구성하려고합니다.

문제 : 스프링 부트는 JPA 데이터 소스, 즉 JDBC 연결 속성을 구성하는 데 필요한 모든 정보를 가지고 있지 않습니다. 해결책 :

  1. JDBC 연결 속성 제공 (최상)
  2. 일부 AutoConfig 클래스를 제외하여 연결 속성 제공 연기 (임시-결국 제거해야 함)

위의 링크 DataSourceAutoConfiguration.class

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

그러나 이것은 나를 위해 작동하지 않았습니다. 대신 2 개의 AutoConfig 클래스를 제외해야했습니다.

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, XADataSourceAutoConfiguration.class})


답변

“데이터 소스를 구성하지 못했습니다”오류. 먼저 데이터 소스를 정의하여 문제를 해결했습니다. 다음으로 데이터 소스를 구성하지 않고 문제를 해결하는 방법에 대해 설명했습니다.

https://www.baeldung.com/spring-boot-failed-to-configure-data-source