2017-10-10 47 views
1

我目前正在創建春啓動的一個項目+反應(自動加載)+ mysql數據庫,但一旦我嘗試創建像this tuto後端,我得到這個錯誤在spring引導+ react + mysql連接器上構建失敗?

錯誤創建名稱爲org.springframework豆。 boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration:通過構造函數參數0表示的不滿足的依賴關係;嵌套異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有可用的javax.sql.DataSource類型的可用bean:預計至少有1個bean有資格作爲autowire候選者。依賴註解:{}

我的pom.xml的是:

<?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.gmed</groupId> 
<artifactId>starter</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>Spring Boot and React starter</name> 
<description>Spring Boot and React starter</description> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.7.RELEASE</version><!-- 1.3.3.RELEASE for the last stable release --> 
    <relativePath /> <!-- lookup parent from repository --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
    <orika-core.version>1.4.6</orika-core.version> 
    <assertj-core.version>3.2.0</assertj-core.version> 
    <lombok.version>1.16.6</lombok.version> 
    <cobertura-plugin.version>2.7</cobertura-plugin.version> 
    <coveralls-plugin.version>4.0.0</coveralls-plugin.version> 
    <frontend-plugin.version>0.0.27</frontend-plugin.version> 
    <node.version>v5.7.0</node.version> 
    <npm.version>3.7.1</npm.version> 
</properties> 

<dependencies> 
    <!-- Spring Boot Starters --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
     <exclusions> 
      <exclusion> 
       <!-- We use HikariCP instead --> 
       <groupId>org.apache.tomcat</groupId> 
       <artifactId>tomcat-jdbc</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

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


    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 


    <!-- Database --> 
    <dependency> 
     <groupId>com.h2database</groupId> 
     <artifactId>h2</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.zaxxer</groupId> 
     <artifactId>HikariCP</artifactId> 
    </dependency> 
    <!-- For MySQL --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.6</version> 
    </dependency> 
    <!-- Other --> 
    <dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-web</artifactId> 

</dependency> 
<dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
    </dependency> 



    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 

    </dependency> 

    <dependency> 
     <groupId>ma.glasnost.orika</groupId> 
     <artifactId>orika-core</artifactId> 
     <version>${orika-core.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.projectlombok</groupId> 
     <artifactId>lombok</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.assertj</groupId> 
     <artifactId>assertj-core</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-jpamodelgen</artifactId> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
     <!-- Cobertura --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
      <version>${cobertura-plugin.version}</version> 
      <configuration> 
       <format>xml</format> 
       <maxmem>256m</maxmem> 
       <aggregate>true</aggregate> 
       <instrumentation> 
        <!-- Exclude JPA meta-model generated classes --> 
        <ignores> 
         <ignore>**/*_.java</ignore> 
        </ignores> 
        <excludes> 
         <exclude>**/*_.class</exclude> 
        </excludes> 
       </instrumentation> 
       <check/> 
      </configuration> 
     </plugin> 
     <!-- Coveralls --> 
     <plugin> 
      <groupId>org.eluder.coveralls</groupId> 
      <artifactId>coveralls-maven-plugin</artifactId> 
      <version>${coveralls-plugin.version}</version> 
      <configuration> 
       <repoToken>your coveralls repository token goes here</repoToken> 
      </configuration> 
     </plugin> 
     <!-- Frontend --> 
     <!-- Frontend --> 
     <plugin> 
      <groupId>com.github.eirslett</groupId> 
      <artifactId>frontend-maven-plugin</artifactId> 
      <version>${frontend-plugin.version}</version> 
      <configuration> 
       <workingDirectory>src/main/frontend</workingDirectory> 
       <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot> 
       <nodeVersion>${node.version}</nodeVersion> 
       <npmVersion>${npm.version}</npmVersion> 
       <installDirectory>target</installDirectory> 
      </configuration> 
      <executions> 
       <execution> 
        <id>install node and npm</id> 
        <goals> 
         <goal>install-node-and-npm</goal> 
        </goals> 
        <phase>generate-resources</phase> 
       </execution> 
       <execution> 
        <id>npm install</id> 
        <goals> 
         <goal>npm</goal> 
        </goals> 
        <configuration> 
         <arguments>install</arguments> 
         <installDirectory>target</installDirectory> 
        </configuration> 
       </execution> 
       <execution> 
        <id>webpack build</id> 
        <goals> 
         <goal>webpack</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
<!-- Repositories only needed if using a milestone or snapshot --> 
<repositories> 
    <repository> 
     <id>spring-snapshots</id> 
     <name>Spring Snapshots</name> 
     <url>https://repo.spring.io/snapshot</url> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </repository> 
    <repository> 
     <id>spring-milestones</id> 
     <name>Spring Milestones</name> 
     <url>https://repo.spring.io/milestone</url> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </repository> 
</repositories> 
<pluginRepositories> 
    <pluginRepository> 
     <id>spring-snapshots</id> 
     <name>Spring Snapshots</name> 
     <url>https://repo.spring.io/snapshot</url> 
     <snapshots> 
      <enabled>true</enabled> 
     </snapshots> 
    </pluginRepository> 
    <pluginRepository> 
     <id>spring-milestones</id> 
     <name>Spring Milestones</name> 
     <url>https://repo.spring.io/milestone</url> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </pluginRepository> 
</pluginRepositories> 

</project> 

我試圖在網絡上的所有解決方案。

感謝

+0

檢查https://stackoverflow.com/questions/32810178/springboot-no-qualifying-bean-of-type-javax-sql-datasource,你有你的依賴列表中的spring-boot-starter-jdbc,並且你有applciation.properties正確創建? –

+0

show log:mvn dependency:tree? –

+0

如果他有starter-data-jpa,他不應該需要starter-jdbc。 – MickG

回答

0

Spring會產生錯誤信息,如果它不能找到數據源參數與建立一個數據源。這些參數來自您的application.properties(基於您鏈接的教程)。最可能的原因是它沒有加載application.properties。

沒有顯示任何代碼,不可能提供更詳細的答案。