2016-06-14 45 views
0

我試圖做一個api。我想嘗試使用Intellij Idea的Spring來實現Hibernate &,我從來沒有使用它們。我不能maven安裝我的空maven項目

我已成功使用intellij創建Spring項目。但即使該項目是'空',我還沒有改變任何東西,我不能做一個maven安裝它。

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.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). 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
    at [...] 

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.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). 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at [...] 

    Caused by: 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). 
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:180) 
    at [...] 

我的pom.xml http://maven.apache.org/xsd/maven-4.0.0.xsd「> 4.0.0

<groupId>com.bloombooking.api</groupId> 
    <artifactId>bloombookingapi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>bloombookingapi</name> 
    <description></description> 

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

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

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

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

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 


</project> 

也許我需要某種的地方屬性,但我不知道哪些和在哪裏把它們...

回答

0

我發現是什麼問題!

所以就是因爲我沒有像你說的那樣配置一些東西。我沒有需要安裝的jdbc(我不知道爲什麼,我並不需要它),但只是把對文件的一些屬性:/main/ressources/application.properties

spring.jpa.database=POSTGRESQL 
spring.datasource.platform=postgres 
spring.jpa.show-sql=true 
spring.jpa.hibernate.ddl-auto=create-drop 
spring.database.driverClassName=org.postgresql.Driver 
spring.datasource.url=jdbc:postgresql://localhost:5432/mybase 
spring.datasource.username=username 
spring.datasource.password=mdp 

THX爲無論如何答案:)

-1

你缺少你的類路徑DB JAR如果你正在使用Maven的 /搖籃,只是包括JDBC驅動程序d依賴於你的POM/gradle 文件。

從這裏摘自: Spring Boot: Unable to configure

至於第一次嘗試的依賴添加到您的POM:

<!-- ORACLE database driver --> 
    <dependency> 
     <groupId>com.oracle</groupId> 
     <artifactId>ojdbc6</artifactId> 
     <version>11.2.0</version> 
    </dependency> 

那麼,如果它不工作與「MVN手動添加安裝:安裝「文件」的目標..

+0

好的,所以我只需要下載postgresql jdbc jar,並把它放在我的項目中的某個地方?究竟在哪裏? (當我試圖把它放在資源中它不會改變任何相同的錯誤) – Antoine

+0

最簡潔的方法是將其安裝在您的本地Maven存儲庫並將其添加爲依賴項。看看http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/ – Pace

+0

好吧,但我怎麼能在我的Intellij上使用這些命令理念? – Antoine