春天的靴子。添加jpa数据库连接并生成方案

时间:2016-07-31 21:59:49

标签: java postgresql spring-boot

我有一个spring boot应用程序,我需要连接到postgres数据库并按实体生成方案。 这是我的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>

这是我的application.properties:

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)}

我还应该做些什么来连接数据库并生成方案?

0 个答案:

没有答案