【问题标题】:I can't maven install my empty maven project我无法安装我的空 Maven 项目
【发布时间】:2016-10-15 11:25:36
【问题描述】:

我正在尝试制作一个 api。我想尝试使用 Intellij Idea 使用 Spring&Hibernate 来实现它,但我从未使用过它们中的任何一个。

我已成功使用 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>

也许我在某个地方需要某种属性,但我不知道哪些属性以及将它们放在哪里...

【问题讨论】:

    标签: java spring hibernate maven intellij-idea


    【解决方案1】:

    我发现了问题所在!

    所以我没有像你说的那样配置一些东西。我不需要安装 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
    

    谢谢你的答案:)

    【讨论】:

      【解决方案2】:

      您的类路径中缺少 DB JAR。如果您正在使用 Maven/Gradle,只需将 JDBC 驱动程序依赖项包含到您的 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 install:install-file”目标手动添加它..

      【讨论】:

      • 好的,所以我只需要下载 postgresql jdbc jar 并将它放在我的项目中的某个地方吗?究竟在哪里? (当我尝试将它放在资源中时,它不会改变任何相同的错误)
      • 最干净的方法是将其安装在本地 maven 存储库中并将其添加为依赖项。看看mkyong.com/maven/…
      • 我建议你安装本地maven并启用命令行...tutorialspoint.com/maven/maven_environment_setup.htm相信我真的很有用..
      猜你喜欢
      • 2016-01-10
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多