Spring 启动 + PostgreSQL : Error creating bean with name 'entityManagerFactory' defined in class path resource

标签 spring postgresql spring-boot

我在连接 Spring Boot 和 PostgreSQL 时遇到问题。我似乎无法让它发挥作用。如果有任何遗漏,我可以给你更多,但现在这些信息已经足够了

完整错误:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project resorts-restful-project: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 

这是我的配置:

应用程序属性:

spring.datasource.url= jdbc:postgresql://localhost:5433/qwerty
spring.datasource.username=postgres spring.datasource.password=postgres@qwerty
spring.jpa.hibernate.ddl-auto=create-drop

我的模型:

package com.fvthree.domain;

import javax.persistence.*;
import java.io.Serializable;

@Entity
public class Resort implements Serializable {
    @Id
    @GeneratedValue
    @Column(name="resorts_id")
    private Long id;

    @Column(name="name")
    private String name;
    @Column(name="location")
    private String location;

    @Column(name="contact_id")
    private Long contactId;

    public Resort() {
    }

    public Resort(Long id, String name, String location, Long contactId) {
        this.id = id;
        this.name = name;
        this.location = location;
        this.contactId = contactId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Long getContactId() {
        return contactId;
    }

    public void setContactId(Long contactId) {
        this.contactId = contactId;
    }
}

最佳答案

确保您设置了所有这些属性:

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=

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

并且您在类上使用 main() 启用了这些注释:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {


    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

} 

关于 Spring 启动 + PostgreSQL : Error creating bean with name 'entityManagerFactory' defined in class path resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42755134/

相关文章:

java - 从工作站中删除 Eclipse。我如何告诉 SVN 忽略文件并填充版本标签

java - Spring单例被调用两次

java - 失去 spring security 记住我重定向后的子域 cookie

java - PUT 请求 : Required request body is missing

python - 将字符串转换为 ISO 日期 python

performance - Postgresql buffers_alloc

postgresql - 在 Amazon ec2 linux 上更改 postgresql 9.3 数据库位置

java - 如何解决此错误 : Caused by: java. lang.InknownClassChangeError: null

java - Spring AOP - 切入点仅在从 lambda 调用 joinPoint.proceed 时应用于方法

java - Spring MVC 如何为 Controller 方法提供注入(inject)