【问题标题】:org.postgresql.util.PSQLException: FATAL: database "pma-springbootdb"org.postgresql.util.PSQLException:致命:数据库“pma-springbootdb”
【发布时间】:2020-09-21 16:48:33
【问题描述】:

我正在开发我的第一个 sprinboot 应用程序,我正在尝试在我的 sprinboot 应用程序中配置 postgreSQL 数据库的属性。当我运行此应用程序时,我收到以下错误。

**org.postgresql.util.PSQLException: FATAL: database "pma-springbootdb" does not exist**
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2533) ~[postgresql-42.2.12.jar:42.2.12]
    at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2645) ~[postgresql-42.2.12.jar:42.2.12]
    at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:138) ~[postgresql-42.2.12.jar:42.2.12]
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:255) ~[postgresql-42.2.12.jar:42.2.12]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.12.jar:42.2.12]
    at org.postgresql.jd
......
2020-06-03 09:33:13.052  WARN 1225 --- [         task-1] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : FATAL: database "pma-springbootdb" does not exist
2020-06-03 09:33:13.078  WARN 1225 --- [  restartedMain] ConfigServletWebServerApplicationContext : **Exception encountered during context initialization - cancelling refresh attempt: nested exception is org.springframework.beans.factory.BeanCreationException:** Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is **org.springframework.beans.BeanInstantiationException: Failed to instantiate** 
**Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter'** defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed   : Invocation of destroy method failed on bean with name 'entityManagerFactory': org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2020-06-03 09:33:13.079  INFO 1225 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-06-03 09:33:13.084  INFO 1225 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-06-03 09:33:13.112  INFO 1225 --- [  restartedMain] ConditionEvaluationReportLoggingListener 
**Caused by: org.springframework.beans.factory.BeanCreationException:** Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeRepository' defined in com.jrp.pma.dao.EmployeeRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext'
  • PostgreSQL 属性

    spring.datasource.url=jdbc:postgresql://localhost:5432/pma-springbootdb

    spring.datasource.username=***
    
    spring.datasource.password=***
    
    spring.datasource.initialization-mode=never
    
    spring.jpa.hibernate.ddl-auto=none
    
    spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
    
    spring.jpa.show-sql=true
    spring.thymeleaf.cache=false
    version=3.0.0
    
  • SQL 查询

    如果不存在则创建序列 employee_seq;

    CREATE TABLE IF NOT EXISTS employee (
    
    employee_id BIGINT NOT NULL DEFAULT nextval('employee_seq') PRIMARY KEY,
    email VARCHAR(100) NOT NULL,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL
    
    );
    
    CREATE SEQUENCE IF NOT EXISTS project_seq;
    
    CREATE TABLE IF NOT EXISTS project (
    
    project_id BIGINT NOT NULL DEFAULT nextval('project_seq') PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    stage VARCHAR(100) NOT NULL,
    description VARCHAR(500) NOT NULL
    
    );
    
    
    CREATE TABLE IF NOT EXISTS project_employee (
    
    project_id BIGINT REFERENCES project, 
    employee_id BIGINT REFERENCES employee
    
    );
    
  • Project.java

     @Entity
        public class Project {
    
    @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "project_seq")
    
    private Long projectId;
        ....
        ....
         }
    

    *

    • Employee.java

    *

    @Entity
    public class Employee {
    @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "employee_seq")
        private long employeeId;
    ...
    ..
    }
    

【问题讨论】:

  • 我回滚了你上次的编辑。如果您在修正错字后遇到其他问题,请提出新问题。不要将您的问题更改为完全不同的问题。您可以删除此问题,因为它只是由拼写错误引起的。
  • 当然。谢谢

标签: java spring postgresql spring-boot jdbc


【解决方案1】:

消息database "pma-springbootdb" does not exist 是不言自明的。

localhost 端口5432 上运行的PostgreSQL 实例中不存在此数据库。可能是错误的数据库名称或错误的实例。

请仔细检查:pma-springbootdb vs pma-springbootbd

【讨论】:

  • 我添加了一个 postgreSQL 数据库的屏幕截图,其中显示了 pma-springbootdb。我认为这不是问题。
  • 您确定这个实例在localhost 上运行,端口为 5432 吗?请发布show listen_addresses; show port;\l 的输出(使用psql CLI 运行)。
  • 谢谢,我拼错了。即使在更正文件名之后,我也得到“由:org.springframework.beans.factory.BeanCreationException:引起:”
  • 请在 Java 代码中仔细检查你有 pma-springbootdb 在 PostgreSQL 中你有 pma-springbootbddb 不同于 bd
  • 如果您还有其他错误信息,请提出另一个问题并提供完整的错误信息。
猜你喜欢
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 2022-08-08
  • 2014-10-27
  • 2015-08-03
  • 2019-05-17
  • 2014-01-28
相关资源
最近更新 更多