Home > Software design >  Spring Boot project doesn't work after switching PCs
Spring Boot project doesn't work after switching PCs

Time:10-14

I know there are similar questions out there but the few that I've found and checked from Google don't seem to help me in any way. So, I reinstalled Windows, and then imported my Spring project back from Github. An issue that I saw straight off the bat is in my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>ValComp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ValComp</name>
<description>Composite value calculator.</description>
<properties>
    <java.version>16</java.version>
</properties>

The Java version that I have installed now is 17, so I tried putting 17 in this line in the file, but in Project>Properties JRE 16 is still referenced and 17 is nowhere to be seen. This aside, my main issue is that when I try running it as a Spring Boot App, I get the following error:

[2m2021-10-13 20:35:18.867[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mcom.valcomp.ValCompApplication          [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2021-10-13 20:35:19.277[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[2m2021-10-13 20:35:19.286[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 4 ms. Found 0 JPA repository interfaces.
[2m2021-10-13 20:35:19.623[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2021-10-13 20:35:19.630[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.apache.catalina.core.StandardService  [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2021-10-13 20:35:19.630[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/9.0.52]
[2m2021-10-13 20:35:19.720[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2021-10-13 20:35:19.720[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 824 ms
[2m2021-10-13 20:35:19.850[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [name: default]
[2m2021-10-13 20:35:19.888[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36morg.hibernate.Version                   [0;39m [2m:[0;39m HHH000412: Hibernate ORM core version 5.4.32.Final
[2m2021-10-13 20:35:19.987[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.hibernate.annotations.common.Version  [0;39m [2m:[0;39m HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
[2m2021-10-13 20:35:20.063[0;39m [32m INFO[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mcom.zaxxer.hikari.HikariDataSource      [0;39m [2m:[0;39m HikariPool-1 - Starting...
[2m2021-10-13 20:35:21.182[0;39m [31mERROR[0;39m [35m11792[0;39m [2m---[0;39m [2m[           main][0;39m [36mcom.zaxxer.hikari.pool.HikariPool       [0;39m [2m:[0;39m HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: FATAL: database "valholder" does not exist
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2552) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2664) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:147) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:273) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.23.jar:42.2.23]
    at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.23.jar:42.2.23]
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]

which is VERY weird since the code worked before the upgrade, and it's supposed to create that database itself. Here's my application.properties file:

spring.datasource.url=jdbc:postgresql://localhost:5432/valholder
spring.datasource.username=postgres
spring.datasource.password=slur123~
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

server.error.include-message=always

Btw, the login credentials from the file work in the SQL Shell, so that ain't the issue. I'd rather not start a new project from zero and get this one running since it would 1). teach me how to handle such issues; 2). have some Github continuity. :)

Any ideas are humbly welcomed.

CodePudding user response:

it's supposed to create that database itself

It's probably not actually meant to create the actual database, but create all the tables and so on (using Hibernate and hibernate.ddl-auto).

Admittedly, the username you're using is postgres, so it could potentially create the database too, but there would need to be a special mechanism before your datasource is initialised with that JDBC URL (since it contains the database name and will try to connect it initially).

It's possible to have such an additional mechanism, but unlikely. (That mechanism would probably have to assume that the postgres maintenance database is used for an initial JDBC connection unrelated to your application datasource, create the database from there, and only then reconnect with the JDBC URL you have for initialising your datasource.)

Your solution would be to create your database in advance (e.g. with psql or pgAdmin). It might also be better practice to use a non-admin user: just create a different user and make it the owner of that new database. (If you create that user with pgAdmin, remember to enable "Can log in", which I'm not sure is enabled by default.)

  • Related