有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javaspringboot。添加jpa数据库连接并生成方案

我有一个spring boot应用程序,我需要连接到postgres数据库并按实体生成scheme。 这是我的maven依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>1.3.7.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1200-jdbc41</version>
    </dependency>

这是我的申请表。特性:

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/my_db
spring.datasource.username=...
spring.datasource.password=...

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create

我还有一个User类,用@EntityUsersRepository表示扩展CrudRepository<User, Long>。 但它不起作用。我有一个例外:

2016-08-01 00:57:56.441 ERROR 17643 --- [main]
o.s.boot.SpringApplication: Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':
Injection of autowired dependencies failed; nested exception is. org.springframework.beans.factory.BeanCreationException:.Could not autowire field: private javax.sql.DataSource
org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [javax.sql.DataSource] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

我还应该做什么来连接到数据库并生成scheme


共 (0) 个答案