I have created a spring boot app with the following setup:
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.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com</groupId>
<artifactId>ticket</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ticket</name>
<description>ticketing microservice</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.github.cliftonlabs</groupId>
<artifactId>json-simple</artifactId>
<version>3.1.1</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.playtika.testcontainers</groupId>
<artifactId>embedded-postgresql</artifactId>
<version>1.43</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
bootstrap-test.properties:
embedded.postgresql.enabled=true
embedded.postgresql.dockerImage=postgres
embedded.postgresql.user=docker
embedded.postgresql.password=docker
embedded.postgresql.schema=test_db
embedded.containers.forceShutdown=true
application-test.properties
spring.datasource.url=jdbc:postgresql://${embedded.postgresql.host}:${embedded.postgresql.port}/${embedded.postgresql.schema}
spring.datasource.username=${embedded.postgresql.user}
spring.datasource.password=${embedded.postgresql.password}
spring.jpa.hibernate.ddl-auto=create
My simple test class:
#AutoConfigureMockMvc
#ActiveProfiles("test")
#SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class TicketControllerTest {
#LocalServerPort
private int port;
#Autowired
private TestRestTemplate restTemplate;
#Test
public void getInfoTest() throws Exception {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/tickets/info",
String.class)).contains("ghix-ticket");
}
#Test
public void postTicket() throws Exception {
UserTicket rt = new UserTicket();
rt.setDetails("Details test");
rt.setSubject("subject test");
rt.setCreatedBy("1");
rt.setCategory("Verify Death");
rt.setType("Document Verification");
rt.setRole("2025");
TkmTickets responseT = this.restTemplate.postForObject("http://localhost:" + port + "/tickets/",
rt, TkmTickets.class);
System.out.println(responseT.getId());
assertThat(responseT.getDescription()).isEqualTo("Details test");
}
}
Things look good on startup:
10:23:46.877 [main] DEBUG org.springframework.core.env.StandardEnvironment - Activating profiles [test]
10:23:46.881 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}
2021-04-07 10:23:47.419 INFO 27556 --- [ main] EmbeddedPostgreSQLBootstrapConfiguration : Starting postgresql server. Docker image: postgres
2021-04-07 10:23:47.469 INFO 27556 --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
2021-04-07 10:23:47.833 INFO 27556 --- [ main] o.t.d.UnixSocketClientProviderStrategy : Accessing docker with local Unix socket
2021-04-07 10:23:47.833 INFO 27556 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2021-04-07 10:23:47.949 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2021-04-07 10:23:47.991 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 20.10.3
API Version: 1.41
Operating System: Docker Desktop
Total Memory: 1989 MB
2021-04-07 10:23:48.250 INFO 27556 --- [ main] o.t.utility.RegistryAuthLocator : Credential helper/store (docker-credential-desktop) does not have credentials for quay.io
2021-04-07 10:23:48.758 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-04-07 10:23:48.758 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
2021-04-07 10:23:48.759 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
2021-04-07 10:23:48.865 INFO 27556 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker environment should have more than 2GB free disk space
2021-04-07 10:23:48.873 INFO 27556 --- [ main] 🐳 [postgres:latest] : Creating container for image: postgres:latest
2021-04-07 10:23:49.006 INFO 27556 --- [ main] 🐳 [postgres:latest] : Starting container with ID: 131caba247444daf5c6cc0cff99e8c3ebfc658d53c36d771aeaa2ba6e9bad4c6
2021-04-07 10:23:49.312 INFO 27556 --- [ main] 🐳 [postgres:latest] : Container postgres:latest is starting: 131caba247444daf5c6cc0cff99e8c3ebfc658d53c36d771aeaa2ba6e9bad4c6
2021-04-07 10:23:50.425 INFO 27556 --- [ main] 🐳 [postgres:latest] : Container postgres:latest started in PT2.966109S
2021-04-07 10:23:50.426 INFO 27556 --- [ main] EmbeddedPostgreSQLBootstrapConfiguration : Started postgresql server. Connection details: {embedded.postgresql.port=55070, embedded.postgresql.host=localhost, embedded.postgresql.schema=test_db, embedded.postgresql.user=docker, embedded.postgresql.password=docker}, JDBC connection url: jdbc:postgresql://localhost:55070/test_db
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.4)
2021-04-07 10:23:50.550 INFO 27556 --- [ main] c.g.ticket.TicketControllerTest : The following profiles are active: test
2021-04-07 10:23:51.041 INFO 27556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-07 10:23:51.087 INFO 27556 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 39 ms. Found 2 JPA repository interfaces.
2021-04-07 10:23:51.173 INFO 27556 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=648ef21c-f385-3b5a-a247-511006c4b8be
2021-04-07 10:23:51.199 INFO 27556 --- [ main] o.s.c.a.ConfigurationClassEnhancer : #Bean method EmbeddedPostgreSQLDependenciesAutoConfiguration.datasourceDependencyPostProcessor is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean javadoc for complete details.
2021-04-07 10:23:51.564 INFO 27556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 0 (http)
2021-04-07 10:23:51.574 INFO 27556 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-04-07 10:23:51.575 INFO 27556 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-04-07 10:23:52.114 INFO 27556 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-04-07 10:23:52.114 INFO 27556 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1560 ms
2021-04-07 10:23:52.320 INFO 27556 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-04-07 10:23:52.384 INFO 27556 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.29.Final
2021-04-07 10:23:52.524 INFO 27556 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-04-07 10:23:52.619 INFO 27556 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-04-07 10:23:52.738 INFO 27556 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
However shorty after that I see it start to tell me it cannot find the tables in the DB:
2021-04-07 10:23:52.778 INFO 27556 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2021-04-07 10:23:52.868 INFO 27556 --- [ main] o.h.e.boot.internal.EnversServiceImpl : Envers integration enabled? : true
2021-04-07 10:23:54.110 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.111 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_ticket_tasks" does not exist, skipping
2021-04-07 10:23:54.112 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.113 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_ticket_tasks" does not exist, skipping
2021-04-07 10:23:54.114 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.114 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_ticket_tasks_aud" does not exist, skipping
2021-04-07 10:23:54.116 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.116 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_tickets" does not exist, skipping
2021-04-07 10:23:54.117 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.117 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_tickets" does not exist, skipping
2021-04-07 10:23:54.118 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.118 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_tickets_aud" does not exist, skipping
2021-04-07 10:23:54.120 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2021-04-07 10:23:54.120 WARN 27556 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "tkm_workflows" does not exist, skipping
I have a look at the db when debugging and sure enough no tables exist on that postgres container, am I missing something in terms of setup, my understanding was that:
spring.jpa.hibernate.ddl-auto=create
Along with the data in data.sql will be all the setup required to create and populate my tables within the DB container.
Here is my dockerFile:
FROM openjdk:8
ADD target/ghix-ticket-0.0.1-SNAPSHOT.jar ghix-ticket-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "ghix-ticket-0.0.1-SNAPSHOT.jar"]
and my dockercompose:
version: "3"
services:
db:
image: postgres
#network_mode: bridge
container_name: db
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=docker
- POSTGRES_USER=docker
- POSTGRES_DB=docker
restart: unless-stopped
# This is my rest api app*****************************************
ghix-ticket:
image: ghix-ticket
#network_mode: bridge
container_name: ghix-ticket
expose:
- 8080
ports:
- 8081:8080
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db/docker
SPRING_DATASOURCE_USERNAME: docker
SPRING_DATASOURCE_PASSWORD: docker
depends_on:
- db
volumes:
- /Users/mcerlane_w/dev/:/var/tmp
restart: unless-stopped
volumes:
postgres-data:
However this is coming from when I am running my tests from IDE or when I run via:
mvn test -Dspring-boot.run.profiles=test
Log from Postgres container:
The files belonging to this database system will be owned by user
"postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2021-04-07 17:55:15.130 UTC [48] LOG: starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-07 17:55:15.131 UTC [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-07 17:55:15.132 UTC [49] LOG: database system was shut down at 2021-04-07 17:55:14 UTC
2021-04-07 17:55:15.134 UTC [48] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2021-04-07 17:55:15.339 UTC [48] LOG: received fast shutdown request
2021-04-07 17:55:15.339 UTC [48] LOG: aborting any active transactions
waiting for server to shut down....2021-04-07 17:55:15.342 UTC [48] LOG: background worker "logical replication launcher" (PID 55) exited with exit code 1
2021-04-07 17:55:15.342 UTC [50] LOG: shutting down
2021-04-07 17:55:15.347 UTC [48] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2021-04-07 17:55:15.459 UTC [1] LOG: starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-04-07 17:55:15.459 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-04-07 17:55:15.460 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-04-07 17:55:15.460 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-04-07 17:55:15.462 UTC [76] LOG: database system was shut down at 2021-04-07 17:55:15 UTC
2021-04-07 17:55:15.466 UTC [1] LOG: database system is ready to accept connections
Related
I am using spring boot 2.5.3 and postgreSQL for backend.
I want this app to run on localhost:5000/api/v1/customers as well as from docker-compose.
application.properties:
server.port=5000
#Database setup
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/customers
spring.datasource.username=postgres
spring.datasource.password=postgres
This works with localhost, with mvn spring-boot:run
But, when I use the following application.properties settings from localhost to db
server.port=5000
#Database setup
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://db:5432/customers
spring.datasource.username=postgres
spring.datasource.password=postgres
Dockerfile
FROM maven:3.8.1-openjdk-11-slim
COPY ./target/customer-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
docker-compose.yml
version: '3.1'
services:
app:
container_name: customer-container
image: customer-image:v1
build: ./
ports:
- "5000:5000"
depends_on:
- db
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=customers
I cannot connect to localhost:5000/api/v1/customers after mvn spring-boot:run
Error:
org.postgresql.util.PSQLException: Connection to db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:303) ~[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]
Tried to create a docker image docker build -t customer-image:v1 .
, and run docker-compose build docker-compose up there are no error.
Logs says it is running on port 5000.
customer-container | 2021-08-29 12:43:42.053 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
customer-container | 2021-08-29 12:43:42.068 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
customer-container | 2021-08-29 12:43:42.069 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.50]
customer-container | 2021-08-29 12:43:42.189 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
customer-container | 2021-08-29 12:43:42.190 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1876 ms
customer-container | 2021-08-29 12:43:42.487 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
customer-container | 2021-08-29 12:43:42.567 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
customer-container | 2021-08-29 12:43:42.702 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
customer-container | 2021-08-29 12:43:42.827 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
customer-container | 2021-08-29 12:43:42.970 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
customer-container | 2021-08-29 12:43:42.995 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
customer-container | 2021-08-29 12:43:43.631 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
customer-container | 2021-08-29 12:43:43.631 WARN 1 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "customer" does not exist, skipping
customer-container | 2021-08-29 12:43:43.642 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
customer-container | 2021-08-29 12:43:43.656 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
customer-container | 2021-08-29 12:43:44.252 WARN 1 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
customer-container | 2021-08-29 12:43:44.991 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5000 (http) with context path ''
customer-container | 2021-08-29 12:43:45.290 INFO 1 --- [ main] c.p.customer.CustomerApplication : Started CustomerApplication in 5.654 seconds (JVM running for 6.531)
This works localhost:5000/api/v1/customers when docker-compose is up.
Is there a way we can have condtional name for host in this line?Is there any other way?
spring.datasource.url=jdbc:postgresql://db:5432/customers
Since the host development environment and the container runtime environment are different, you can use environment variables to differentiate between them. Spring Boot knows how to set Spring properties from environment variables. So I'd recommend:
In your application.properties file, set spring.datasource.url to the localhost URL you'd use in development.
In your Compose setup, set the SPRING_DATASOURCE_URL environment variable to the name specific to that Compose setup
version: '3.8'
services:
db: { ... }
app:
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/customers
...
Do not create a separate Spring profile per environment; you would not want to recompile your jar file if you changed the database name or password, or deployed this in Kubernetes, or used a cloud-hosted database like Amazon RDS, or...
So, you want to be able to run both locally and from docker?
If that's the case, you need to extract the database connection string to an environment variable that you set at runtime
spring.datasource.url = ${DB_HOST}:${DB_PORT}/
spring.datasource.username = ${DB_USERNAME}
spring.datasource.password = ${DB_PASSWD}
Or you can introduce two different property files that get set from a Spring profile, which you also would set at runtime; Refer SPRING_PROFILES_ACTIVE environment variable
Based on what I see, you are not supposed to use localhost on spring.datasource.url because your docker is within the container itself, you should be using
jdbc:postgresql://host.docker.internal:5432/customers instead. For more details, you can view from this link https://docs.docker.com/desktop/windows/networking/#i-cannot-ping-my-containers
Is there a way we can have condtional name for host in this line?Is there any other way?
As for this, it would be prefered to set it as an environmetn variable on your docker compose file and connect using dbconn url
If you are using linux as your operating system on which you are running your docker , you can set this property
network_mode: host
on both the containers, this will attach your container's port to your localhost port.
You will need to remove the port forwarding config for this to work.
I have a problem since I export and import a spring project, and it is that now it takes more than 70 seconds to start. Get stuck in Triggering deferred initialization of Spring Data repositories ...
This is the log of the console:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2021-01-19 21:00:48.994 INFO 15368 --- [ restartedMain] com.practica.PracticaFinalApplication : Starting PracticaFinalApplication on DESKTOP-BG6SBT4 with PID 15368 (D:\workspace-spring-tool-suite-4-4.8.0.RELEASE\PRACTICA_FINAL\target\classes started by dani_ in D:\workspace-spring-tool-suite-4-4.8.0.RELEASE\PRACTICA_FINAL)
2021-01-19 21:00:48.998 INFO 15368 --- [ restartedMain] com.practica.PracticaFinalApplication : No active profile set, falling back to default profiles: default
2021-01-19 21:00:49.051 INFO 15368 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\dani_\.m2\repository\com\oracle\database\jdbc\ojdbc8\19.3.0.0\ojdbc8-19.3.0.0.jar referenced one or more files that do not exist: file:/C:/Users/dani_/.m2/repository/com/oracle/database/jdbc/ojdbc8/19.3.0.0/oraclepki.jar
2021-01-19 21:00:49.051 INFO 15368 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\dani_\.m2\repository\com\oracle\database\security\oraclepki\19.3.0.0\oraclepki-19.3.0.0.jar referenced one or more files that do not exist: file:/C:/Users/dani_/.m2/repository/com/oracle/database/security/oraclepki/19.3.0.0/osdt_core.jar,file:/C:/Users/dani_/.m2/repository/com/oracle/database/security/oraclepki/19.3.0.0/osdt_cert.jar,file:/C:/Users/dani_/.m2/repository/com/oracle/database/security/oraclepki/oracle.osdt/osdt_core.jar,file:/C:/Users/dani_/.m2/repository/com/oracle/database/security/oraclepki/oracle.osdt/osdt_cert.jar
2021-01-19 21:00:49.052 INFO 15368 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-01-19 21:00:49.052 INFO 15368 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-01-19 21:00:49.767 INFO 15368 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2021-01-19 21:00:49.848 INFO 15368 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 75ms. Found 6 JPA repository interfaces.
2021-01-19 21:00:50.143 INFO 15368 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$5974c00c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-01-19 21:00:50.203 INFO 15368 --- [ restartedMain] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2021-01-19 21:00:50.575 INFO 15368 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8085 (http)
2021-01-19 21:00:50.586 INFO 15368 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-19 21:00:50.587 INFO 15368 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2021-01-19 21:00:50.709 INFO 15368 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-19 21:00:50.710 INFO 15368 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1658 ms
2021-01-19 21:00:50.967 INFO 15368 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-19 21:00:51.007 INFO 15368 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-01-19 21:00:51.055 INFO 15368 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2021-01-19 21:00:51.101 WARN 15368 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-01-19 21:00:51.160 INFO 15368 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2021-01-19 21:00:51.267 INFO 15368 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-01-19 21:00:51.313 INFO 15368 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#5548d944, org.springframework.security.web.context.SecurityContextPersistenceFilter#52db2e9a, org.springframework.security.web.header.HeaderWriterFilter#2682a673, org.springframework.security.web.csrf.CsrfFilter#384244c7, org.springframework.security.web.authentication.logout.LogoutFilter#60a9bf00, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#14f3c976, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#14a70864, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#9aabdd5, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#61618c62, org.springframework.security.web.session.SessionManagementFilter#1e6efa12, org.springframework.security.web.access.ExceptionTranslationFilter#72c01891, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#43f59fcf]
2021-01-19 21:00:51.534 INFO 15368 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-01-19 21:00:51.551 INFO 15368 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
2021-01-19 21:00:51.756 INFO 15368 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2021-01-19 21:00:51.825 INFO 15368 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8085 (http) with context path ''
2021-01-19 21:00:51.828 INFO 15368 --- [ restartedMain] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2021-01-19 21:02:03.729 WARN 15368 --- [ task-1] o.h.b.i.InFlightMetadataCollectorImpl : HHH000069: Duplicate generator name sequence
2021-01-19 21:02:03.741 WARN 15368 --- [ task-1] o.h.b.i.InFlightMetadataCollectorImpl : HHH000069: Duplicate generator name sequence
2021-01-19 21:02:03.744 WARN 15368 --- [ task-1] o.h.b.i.InFlightMetadataCollectorImpl : HHH000069: Duplicate generator name sequence
2021-01-19 21:02:04.203 INFO 15368 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-01-19 21:02:04.211 INFO 15368 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-01-19 21:02:04.639 INFO 15368 --- [ restartedMain] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2021-01-19 21:02:04.647 INFO 15368 --- [ restartedMain] com.practica.PracticaFinalApplication : Started PracticaFinalApplication in 76.038 seconds (JVM running for 77.006)
And this is the pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.4.RELEASE
com.practica
PRACTICA_FINAL
0.0.1-SNAPSHOT
war
PRACTICA_FINAL
Practica
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.24</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
In case it works for someone, I found the solution. I just had to add these two lines in my properties file and I went from starting in 70 seconds to starting in 4 seconds
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.Oracle12cDialect
I am trying to build my docker image for my spring boot application but keep encountering this error:
:: Spring Boot :: (v2.2.5.RELEASE)
2020-05-31 02:18:39.820 INFO 63 --- [ main] c.g.Apollo.ApolloApplicationTests : Starting ApolloApplicationTests on 4b284b60945e with PID 63 (started by root in /build)
2020-05-31 02:18:39.838 INFO 63 --- [ main] c.g.Apollo.ApolloApplicationTests : No active profile set, falling back to default profiles: default
2020-05-31 02:18:42.208 INFO 63 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-31 02:18:42.467 INFO 63 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 216ms. Found 3 JPA repository interfaces.
2020-05-31 02:18:44.902 INFO 63 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-31 02:18:46.575 ERROR 63 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.4.2.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.2.jar:na]
Terminal when successfully running in intellij:
:: Spring Boot :: (v2.2.5.RELEASE)
2020-05-31 01:04:39.322 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : Starting ApolloApplication on asd-PC with PID 19524 (C:\Projects\Apollo\target\classes started by asd in C:\Projects\Apollo)
2020-05-31 01:04:39.324 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : No active profile set, falling back to default profiles: default
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in C:\Users\asd\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/C:/Users/asd/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-05-31 01:04:39.354 INFO 19524 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-05-31 01:04:39.785 INFO 19524 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-31 01:04:39.846 INFO 19524 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 54ms. Found 3 JPA repository interfaces.
2020-05-31 01:04:40.214 INFO 19524 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-31 01:04:40.220 INFO 19524 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-31 01:04:40.221 INFO 19524 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-05-31 01:04:40.293 INFO 19524 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-31 01:04:40.293 INFO 19524 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 939 ms
2020-05-31 01:04:40.365 INFO 19524 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-31 01:04:40.702 INFO 19524 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-31 01:04:40.731 INFO 19524 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-31 01:04:40.800 INFO 19524 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-05-31 01:04:40.919 INFO 19524 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-31 01:04:41.006 INFO 19524 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-05-31 01:04:41.407 INFO 19524 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-31 01:04:41.413 INFO 19524 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-31 01:04:41.650 WARN 19524 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-05-31 01:04:41.717 INFO 19524 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-31 01:04:41.967 INFO 19524 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-05-31 01:04:41.995 INFO 19524 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-31 01:04:41.997 INFO 19524 --- [ restartedMain] c.g.Apollo.ApolloApplication : Started ApolloApplication in 2.911 seconds (JVM running for 3.899)
My Dockerfile:
FROM maven:3.6.3-jdk-11-slim AS MAVEN_BUILD
COPY pom.xml /build/
COPY src /build/src/
WORKDIR /build/
RUN mvn package
FROM openjdk:11-jre-alpine
WORKDIR /app
COPY --from=MAVEN_BUILD /build/target/*.war /app/app.war
ENTRYPOINT ["java", "-jar", "app.war"]
My application.properties:
## GraphQL SPQR ##
server.port=8080
graphql.spqr.gui.enabled=true
graphql.spqr.http.endpoint=/graphql
graphql.spqr.ws.endpoint=/graphql
## Database Properties ##
spring.datasource.url=jdbc:mysql://localhost:3306/innodb
spring.datasource.username=root
spring.datasource.password=1234
My application works when I build and run the project in Intellij but not when I try and build my docker image. I am using MySQL and have just been connecting on localhost on port 3306.
The error message seems to indicate the issue is failing to connect to the database. From your settings, it appears that you are trying to connect to the DB using localhost:3306. That will not work when you are running the application in a container because docker creates its own network which is separate from you machine’s network. So, localhost in the container does not refer to your machine.
You need to instead setup a docker network that will allow your container to access the database in a specific IP address.
Here is an article with the specifics:
https://nickjanetakis.com/blog/docker-tip-35-connect-to-a-database-running-on-your-docker-host
Note that I have assumed from your post, that the DB is installed in your host machine. If it is not and the DB is running in its own container, the you need to create a docker network and attach both containers to that network.
I had the same issue and resolved it by changing localhost to the service name on which MySQL was running.
Below is my docker-compose and application.properties files
docker-compose.yml
version: '3.8'
services:
app:
container_name: tvms
build:
context: .
dockerfile: Dockerfile
tty: true
volumes:
- ../..:/workspaces:cached
ports:
- 8990:8990
networks:
- impaq
links:
- db:db
db:
image: percona:8.0
privileged: true
restart: always
container_name: standalone-mysql
environment:
MYSQL_ROOT_PASSWORD: ****
volumes:
- perconadata:/var/lib/mysql
ports:
- 3306:3306
networks:
- impaq
networks:
impaq:
volumes:
perconadata:
application.propeties
#datasource
spring.datasource.url=jdbc:mysql://db:3306/db_name
spring.datasource.username=root
spring.datasource.password=*****
For me below solution worked
change your datasource url from
This:
spring.datasource.url=jdbc:mysql://localhost:3306/innodb
To:
spring.datasource.url=jdbc:mysql://localhost:3306/innodb?useSSL=false
I'm following a tutorial about Eureka to start up a sample eureka server ,I followed exactly the same steps but i get a whitelabel insteed of eureka dashbord, I will share with you all the configuration that I made
the POM.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com..discovery.service</groupId>
<artifactId>descoveryservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>descoveryservice</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
application.properties :
server.port=8010
spring.application.name=discoveryservice
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka
and the finally the console :
2020-05-07 16:15:59.358 INFO 21060 --- [ main] o.s.core.annotation.AnnotationUtils : Failed to introspect annotations on class org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceBootstrapConfiguration: java.lang.IllegalStateException: Could not obtain annotation attribute value for public abstract java.lang.Class[] org.springframework.boot.autoconfigure.condition.ConditionalOnClass.value()
2020-05-07 16:15:59.679 INFO 21060 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$97f8ff4f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2020-05-07 16:16:01.722 INFO 21060 --- [ main] c.d.s.d.DescoveryserviceApplication : No active profile set, falling back to default profiles: default
2020-05-07 16:16:02.829 WARN 21060 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2020-05-07 16:16:03.242 INFO 21060 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=889ab658-056e-3973-ba9c-f9fdd0f82c43
2020-05-07 16:16:03.378 INFO 21060 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$97f8ff4f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-07 16:16:04.447 INFO 21060 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)
2020-05-07 16:16:04.491 INFO 21060 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-07 16:16:04.491 INFO 21060 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2020-05-07 16:16:04.509 INFO 21060 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk-11.0.6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk-11.0.6/bin/server;C:/Program Files/Java/jdk-11.0.6/bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\novatim\AppData\Local\Microsoft\WindowsApps;C:\Users\novatim\Desktop\apache-maven-3.6.3-bin\apache-maven-3.6.3\bin;C:\Program Files\Java\jdk-11.0.6\bin;;C:\Users\novatim\Desktop\eclipse-jee-2019-12-R-win32-x86_64\eclipse;;.]
2020-05-07 16:16:04.768 INFO 21060 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-07 16:16:04.768 INFO 21060 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2996 ms
2020-05-07 16:16:04.935 WARN 21060 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-05-07 16:16:04.936 INFO 21060 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-05-07 16:16:04.962 INFO 21060 --- [ main] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#13ed066e
2020-05-07 16:16:06.652 INFO 21060 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-05-07 16:16:08.337 INFO 21060 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2020-05-07 16:16:08.963 WARN 21060 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-05-07 16:16:08.964 INFO 21060 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-05-07 16:16:09.222 INFO 21060 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-07 16:16:10.021 INFO 21060 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-05-07 16:16:10.174 INFO 21060 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2020-05-07 16:16:10.226 INFO 21060 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2020-05-07 16:16:10.229 INFO 21060 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
2020-05-07 16:16:10.243 INFO 21060 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1588860970242 with initial instances count: 0
2020-05-07 16:16:10.250 INFO 21060 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application discoveryservice with eureka with status UP
2020-05-07 16:16:10.326 INFO 21060 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''
2020-05-07 16:16:10.333 INFO 21060 --- [ main] c.d.s.d.DescoveryserviceApplication : Started DescoveryserviceApplication in 13.391 seconds (JVM running for 14.094)
2020-05-07 16:16:17.202 INFO 21060 --- [nio-8010-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-05-07 16:16:17.204 INFO 21060 --- [nio-8010-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-05-07 16:16:17.223 INFO 21060 --- [nio-8010-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 19 ms
I do not know where the problem is it has been several hours that I am looking for a solution, if you have ideas do not hesitate to share them,
Thanks .
I guess you didn't add #EnableEurekaServer annotation to your main app
It should be like this
#SpringBootApplication
#EnableEurekaServer
public class DiscoveryServerApplication {
…
}
I have packaged my spring boot rest backend with mvn package.
When I run the jar on the server with java -jar ... the application starts and gets killed after a few seconds.
I also see that on the linux top view, that the java process goes over 300% CPU. Is that maybe the reason the process gets killed? And if yes, what can I do?
My spring boot application is not very big. Actually its almost empty.
Logs:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.2.RELEASE)
2020-01-26 07:40:36.423 INFO 8144 --- [ main] d.c.c.CarorderprocessApplication : Starting CarorderprocessApplication v0.0.1-SNA
PSHOT on dedi1055.your-server.de with PID 8144 (/usr/www/users/waqfek/software_backend/carorderprocess-0.0.1-SNAPSHOT.jar started by waqfek in /us
r/www/users/waqfek/software_backend)
2020-01-26 07:40:36.426 INFO 8144 --- [ main] d.c.c.CarorderprocessApplication : No active profile set, falling back to default
profiles: default
2020-01-26 07:40:36.487 INFO 8144 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servle
t.context.AnnotationConfigServletWebServerApplicationContext#5cbc508c: startup date [Sun Jan 26 07:40:36 CET 2020]; root of context hierarchy
2020-01-26 07:40:37.614 INFO 8144 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotati
on.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerB
ySpringCGLIB$$d289c8bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-26 07:40:37.915 INFO 8144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2020-01-26 07:40:37.939 INFO 8144 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-26 07:40:37.940 INFO 8144 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2020-01-26 07:40:37.949 INFO 8144 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library whi
ch allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-lin
ux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2020-01-26 07:40:38.014 INFO 8144 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationCon
text
2020-01-26 07:40:38.014 INFO 8144 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization com
pleted in 1530 ms
2020-01-26 07:40:38.159 INFO 8144 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to:
[/*]
2020-01-26 07:40:38.159 INFO 8144 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [
/*]
2020-01-26 07:40:38.159 INFO 8144 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to:
[/*]
2020-01-26 07:40:38.159 INFO 8144 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*
]
2020-01-26 07:40:38.160 INFO 8144 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to
: [/*]
2020-01-26 07:40:38.160 INFO 8144 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2020-01-26 07:40:38.302 INFO 8144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-01-26 07:40:38.306 WARN 8144 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2020-01-26 07:40:38.491 INFO 8144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-01-26 07:40:38.534 INFO 8144 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2020-01-26 07:40:38.548 INFO 8144 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-01-26 07:40:38.625 INFO 8144 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2020-01-26 07:40:38.627 INFO 8144 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-01-26 07:40:38.661 INFO 8144 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-01-26 07:40:38.824 INFO 8144 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2020-01-26 07:40:39.086 INFO 8144 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-01-26 07:40:39.172 INFO 8144 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-01-26 07:40:39.406 INFO 8144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#5cbc508c: startup date [Sun Jan 26 07:40:36 CET 2020]; root of context hierarchy
2020-01-26 07:40:39.444 WARN 8144 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-01-26 07:40:39.492 INFO 8144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2020-01-26 07:40:39.494 INFO 8144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2020-01-26 07:40:39.526 INFO 8144 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-01-26 07:40:39.526 INFO 8144 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2020-01-26 07:40:39.867 INFO 8144 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 8167df1e-24d1-4ebf-bb03-53e2385a1229
2020-01-26 07:40:40.030 INFO 8144 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#d2de489, org.springframework.security.web.context.SecurityContextPersistenceFilter#28cda624, org.springframework.security.web.header.HeaderWriterFilter#5340477f, org.springframework.security.web.csrf.CsrfFilter#6f15d60e, org.springframework.security.web.authentication.logout.LogoutFilter#71687585, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#66ea810, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#5276d6ee, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#2f953efd, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#7eecb5b8, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#475c9c31, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#14bdbc74, org.springframework.security.web.session.SessionManagementFilter#7139992f, org.springframework.security.web.access.ExceptionTranslationFilter#446a1e84, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#169bb4dd]
2020-01-26 07:40:40.112 INFO 8144 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-01-26 07:40:40.113 INFO 8144 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2020-01-26 07:40:40.118 INFO 8144 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2020-01-26 07:40:40.142 INFO 8144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2020-01-26 07:40:40.145 INFO 8144 --- [ main] d.c.c.CarorderprocessApplication : Started CarorderprocessApplication in 4.002 seconds (JVM running for 4.521)
Killed
...
top - 08:51:43 up 137 days, 11:30, 2 users, load average: 0.86, 0.39, 0.30
Tasks: 4 total, 1 running, 3 sleeping, 0 stopped, 0 zombie
%Cpu(s): 30.7 us, 0.9 sy, 0.0 ni, 68.1 id, 0.2 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem : 16119112 total, 4416660 free, 7332300 used, 4370152 buff/cache
KiB Swap: 4194300 total, 3625572 free, 568728 used. 8221460 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
20338 waqfek 20 0 7069792 299952 16808 S 247.5 1.9 0:07.45 java
16765 waqfek 20 0 38960 3032 2704 R 0.0 0.0 0:00.57 top
27373 waqfek 20 0 14092 3600 3048 S 0.0 0.0 0:00.16 bash
28746 waqfek 20 0 14072 3524 2988 S 0.0 0.0 0:00.00 bash
I only have three files in my project:
1.:
package ...
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class CarorderprocessApplication {
public static void main(String[] args) {
SpringApplication.run(CarorderprocessApplication.class, args);
}
}
Then I have application.properties file with information for database connection and port.
pom.xml:
https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.2.RELEASE
de.countandcare
carorderprocess
0.0.1-SNAPSHOT
carorderprocess
Demo project for Spring Boot
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Some ideas to check:
Try to run as detached: java -jar yourapp.jar &
Try ( just once ) to run under root
Check logs: journalctl -ex for details of who exactly has killed your application.
Depends on results, can plan next steps - typically which settings to adjust.