Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 弹簧靴&x2B;PostgreSQL:创建名为';实体管理工厂&x27;在类路径资源中定义_Spring_Postgresql_Spring Boot - Fatal编程技术网

Spring 弹簧靴&x2B;PostgreSQL:创建名为';实体管理工厂&x27;在类路径资源中定义

Spring 弹簧靴&x2B;PostgreSQL:创建名为';实体管理工厂&x27;在类路径资源中定义,spring,postgresql,spring-boot,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 runni

我在将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 
以下是我的配置:

application.properties:

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()类上启用了这些注释:


我已经解决了这个问题

application.properties文件需要完整:

# Configure postgres

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/qweqwe
spring.datasource.username=postgres
spring.datasource.password=dontcopythis
我还将@EntityScan和@EnableJpaRepositories添加到主目录中:

package com.fvthree;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EntityScan(basePackages = {"com.fvthree.domain" })
@EnableJpaRepositories(basePackages = {"com.fvthree.repository"})
public class ResortsRestfulProjectApplication {

    public static void main(String[] args) {
        SpringApplication.run(ResortsRestfulProjectApplication.class, args);
    }
}
(1) 在文件
application.properties
中,请注意
spring.datasource.username=postgres-spring.datasource.password=postgres@qwerty
是两行,而不是一行

(2) 由于此错误:

在以下情况下,对方言解析信息的访问不能为空: 未设置“hibernate.dialogue”

你失踪了
hibernate.dia方言=…

例如,如果使用PostgreSQL 9.5,则
hibernate.dialogue=org.hibernate.dialogue.postgresql95dialogue


参考资料:

有没有办法让org.hibernate.dialent.postgresql95dialent使用spring启动程序数据jpa:1.5.3.RELEASE?它不包含hibernate的版本,而hibernate的版本应该是这样的。您应该使用最新的PostgreSQL版本,然后使用
org.hibernate.dialent.PostgreSQL95dialent
not
org.hibernate.dialent.PostgreSQLdialent
Spring Boot 1.5.3.RELEASE使用hibernate托管依赖版本5.0.12.Final。请参阅:(hibernate orm部分),您必须覆盖托管依赖项版本。但这会使应用程序不稳定。
package com.fvthree;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EntityScan(basePackages = {"com.fvthree.domain" })
@EnableJpaRepositories(basePackages = {"com.fvthree.repository"})
public class ResortsRestfulProjectApplication {

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