2017-05-11 16 views
0

私はSpringデータJPAを使用する次のSpringブートプロジェクトを持っています。私の残りのコントローラは、以下のannotations-で注釈されている:除外パラメータは@EnableAutoConfigurationに必要とされる理由Springブート - Hibernateを手動で設定するときに除外が必要なのはなぜですか?

@SpringBootApplication 
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 
@ComponentScan({ "com.foo.bar"}) 
public class RESTService { 

私の質問はありますか?私は除外せずにアプリケーションを起動した場合、私は、次のexceptions-を得る:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). 

は今、私は手動で私のプロジェクトの中から休止状態を設定しています。

私は、Spring Bootはクラスパス上で春のデータを見るので、JDBCとHibernate JPAを自動設定しようとしています。しかし、それでMongoや他のデータベースソリューションを自動設定しようとしないのはなぜですか?

ここで何が起こっているのか理解してもらえますか?

マイPOMファイルは - :あなたのクラスパスにそれぞれのスターター依存性を持っている場合

<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.foo.bar</groupId> 
    <artifactId>Project</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>REST Service</name> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.1.RELEASE</version> 
    </parent> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.postgresql</groupId> 
      <artifactId>postgresql</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>net.sourceforge.javacsv</groupId> 
      <artifactId>javacsv</artifactId> 
      <version>2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.jackson</groupId> 
      <artifactId>jackson-core-asl</artifactId> 
      <version>1.1.0</version> 
     </dependency> 
     <!-- 
     <dependency> 
       <groupId>org.fosstrak.epcis</groupId> 
       <artifactId>epcis-repository</artifactId> 
       <version>0.5.0</version> 
      </dependency> 
      --> 
      <dependency> 
       <groupId>org.fosstrak.epcis</groupId> 
       <artifactId>epcis-repository</artifactId> 
       <version>0.5.0</version> 
       <scope>system</scope> 
       <systemPath>${project.basedir}/lib/epcis-commons-0.5.0.jar</systemPath> 
      </dependency> 
    </dependencies> 
    <properties> 
     <java.version>1.7</java.version> 
    </properties> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
       <configuration> 
        <mainClass>com.foo.bar.RESTService</mainClass> 
        <addResources>true</addResources> 
        <layout>JAR</layout> 
        </configuration> 
       <executions> 
        <execution> 
         <goals> 
         <goal>repackage</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 
+1

pomファイルを投稿してください。 @SpringBootApplicationは、メインのアプリケーションクラスに配置する必要があります。 RESTServiceクラスはメインクラスですか? – MrKiller21

+0

@ MrKiller21私のPOMファイルを追加しました –

+1

Spring Bootは、クラスパスで見つかったものだけを設定します。もしあなたがmongoを持っていなければ、なぜmongoを設定する必要がありますか? –

答えて

0

春はモンゴを自動構成します。例えば

:あなたはpostet例外について

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

は、それはあなたがあなたのDATABASEDRIVERを設定してやりなさいと言っています。あなたのプロパティの行に沿ってsometingする必要があります:

spring.datasource.driver-class-name: oracle.jdbc.pool.OracleDataSource 
spring.datasource.url: jdbc:oracle:thin:@<host>:1521:<schema> 
spring.datasource.username: <user> 
spring.datasource.password: <password> 

あなたはもちろんどのデータベースを使用しているかによって異なります。

+0

それは本当ですか? JPAの自動設定は何ですか? –

+0

説明を少し変更しました。今はっきりしていることを願っています。 –

0

あなたのpom.xmlに基づいて、私はあなたがPostgresを使用していると仮定します。 application.propertiesファイルでデータソースを構成したことを確認してください。例外は、それが誤って構成されていることを示唆することがあります

spring.datasource.url=jdbc:postgresql://localhost/testdb 
spring.datasource.username=postgres 
spring.datasource.password=123 
関連する問題