The goal: Uninstall flyway from my Spring Maven project !
Maybe my question is more global and consists of how to get rid of dependecies or libraries....
The context:
My project is called "Meetzicker" it will be a restfull API to meet musicians.
I will dockerize it and use docker-compose with many services:
my API
postgres db
pgAdmin to manage DB
and later flyway but not for now !
If you have advices I accept them gladly !
enter image description here
First I build an image of my project with the 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.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.praline40</groupId>
<artifactId>meetzicker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>MeetZicker REST API</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version> 2.0.1.Final </version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.1</version>
<configuration>
<images>
<image>
<name>${project.artifactId}</name>
<build>
<dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
<assembly>
<mode>dir</mode>
<targetDir>/var/lib/${project.artifactId}</targetDir>
<descriptor>${project.basedir}/src/main/docker/assembly.xml</descriptor>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build</id>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The last part of the pom (between ... ) builds my image automatically when I call:
~/Documents/MeetZicker/BACK/MeetZicker/MeetZicker$ mvn clean install -DskipTests=true
I am using docker-composed with 3 services:
# meetzicker/docker-compose.yml
version: "3.3"
services:
db:
image: postgres:${POSTGRES_VERSION}
container_name: db
network_mode: bridge
volumes:
- db-data:/var/lib/postgresql/data
expose:
- 5432
ports:
- 5432:5432
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4
network_mode: bridge
container_name: pgadmin4
volumes:
- pgadmin-data:/var/lib/pgadmin
expose:
- 5050
ports:
- 5051:5050
links:
- db:pgsql-server
environment:
PGADMIN_DEFAULT_EMAIL: praline40#hotmail.fr
PGADMIN_DEFAULT_PASSWORD: ${POSTGRES_PASSWORD}
PGADMIN_PORT: 5050
restart: unless-stopped
meetzicker:
image: meetzicker
network_mode: bridge
container_name: meetzicker
volumes:
- meetzicker-data:/var/lib/meetzicker
expose:
- 8080
ports:
- 8080:8080
restart: unless-stopped
depends_on:
- db
volumes:
db-data:
pgadmin-data:
meetzicker-data:
When I call docker-compose:
jules#jules-MS-7B51:~/Documents/MeetZicker/BACK/MeetZicker/MeetZicker/src/main/docker$ docker-compose up
I have this error:
jules#jules-MS-7B51:~/Documents/MeetZicker/BACK/MeetZicker/MeetZicker/src/main/docker$ docker-compose up
WARNING: Found orphan containers (my-flyway) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
db is up-to-date
Starting pgadmin4 ... done
Starting meetzicker ... done
Attaching to db, meetzicker, pgadmin4
meetzicker | wait-for-it.sh: waiting 15 seconds for db:5432
db |
db | PostgreSQL Database directory appears to contain a database; Skipping initialization
db |
db | LOG: database system was shut down at 2021-05-14 13:52:50 UTC
db | LOG: MultiXact member wraparound protections are now enabled
db | LOG: database system is ready to accept connections
db | LOG: autovacuum launcher started
pgadmin4 | [2021-05-14 14:16:16 +0000] [1] [INFO] Starting gunicorn 20.1.0
pgadmin4 | [2021-05-14 14:16:16 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmin4 | [2021-05-14 14:16:16 +0000] [1] [INFO] Using worker: threads
pgadmin4 | [2021-05-14 14:16:16 +0000] [82] [INFO] Booting worker with pid: 82
meetzicker | wait-for-it.sh: timeout occurred after waiting 15 seconds for db:5432
meetzicker |
meetzicker | . ____ _ __ _ _
meetzicker | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
meetzicker | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
meetzicker | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
meetzicker | ' |____| .__|_| |_|_| |_\__, | / / / /
meetzicker | =========|_|==============|___/=/_/_/_/
meetzicker | :: Spring Boot :: (v2.3.4.RELEASE)
meetzicker |
meetzicker | 2021-05-14 14:16:29.399 INFO 43 --- [ main] c.p.MeetZicker.MeetZickerApplication : Starting MeetZickerApplication v0.0.1-SNAPSHOT on c9ed3b2b0bd9 with PID 43 (/var/lib/meetzicker/meetzicker.jar started by root in /var/lib/meetzicker)
meetzicker | 2021-05-14 14:16:29.401 INFO 43 --- [ main] c.p.MeetZicker.MeetZickerApplication : The following profiles are active: dev
meetzicker | 2021-05-14 14:16:29.849 INFO 43 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
meetzicker | 2021-05-14 14:16:29.918 INFO 43 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 62ms. Found 12 JPA repository interfaces.
meetzicker | 2021-05-14 14:16:30.323 INFO 43 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
meetzicker | 2021-05-14 14:16:30.331 INFO 43 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
meetzicker | 2021-05-14 14:16:30.331 INFO 43 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
meetzicker | 2021-05-14 14:16:30.368 INFO 43 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
meetzicker | 2021-05-14 14:16:30.368 INFO 43 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 936 ms
meetzicker | 2021-05-14 14:16:30.445 WARN 43 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unsatisfied dependency expressed through method 'flywayInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingException: Cannot find migration scripts in: [classpath:db/migration] (please add migration scripts or check your Flyway configuration)
meetzicker | 2021-05-14 14:16:30.447 INFO 43 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
meetzicker | 2021-05-14 14:16:30.453 INFO 43 --- [ main] ConditionEvaluationReportLoggingListener :
meetzicker |
meetzicker | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
meetzicker | 2021-05-14 14:16:30.454 ERROR 43 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
meetzicker |
meetzicker | ***************************
meetzicker | APPLICATION FAILED TO START
meetzicker | ***************************
meetzicker |
meetzicker | Description:
meetzicker |
meetzicker | Flyway failed to initialize: none of the following migration scripts locations could be found:
meetzicker |
meetzicker | - classpath:db/migration
meetzicker |
meetzicker |
meetzicker | Action:
meetzicker |
meetzicker | Review the locations above or check your Flyway configuration
meetzicker |
meetzicker | wait-for-it.sh: waiting 15 seconds for db:5432
meetzicker | wait-for-it.sh: timeout occurred after waiting 15 seconds for db:5432
meetzicker |
meetzicker | . ____ _ __ _ _
meetzicker | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
meetzicker | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
meetzicker | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
meetzicker | ' |____| .__|_| |_|_| |_\__, | / / / /
meetzicker | =========|_|==============|___/=/_/_/_/
meetzicker | :: Spring Boot :: (v2.3.4.RELEASE)
meetzicker |
meetzicker | 2021-05-14 14:16:46.742 INFO 44 --- [ main] c.p.MeetZicker.MeetZickerApplication : Starting MeetZickerApplication v0.0.1-SNAPSHOT on c9ed3b2b0bd9 with PID 44 (/var/lib/meetzicker/meetzicker.jar started by root in /var/lib/meetzicker)
meetzicker | 2021-05-14 14:16:46.743 INFO 44 --- [ main] c.p.MeetZicker.MeetZickerApplication : The following profiles are active: dev
meetzicker | 2021-05-14 14:16:47.199 INFO 44 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
meetzicker | 2021-05-14 14:16:47.268 INFO 44 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 63ms. Found 12 JPA repository interfaces.
meetzicker | 2021-05-14 14:16:47.673 INFO 44 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
meetzicker | 2021-05-14 14:16:47.681 INFO 44 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
meetzicker | 2021-05-14 14:16:47.681 INFO 44 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
meetzicker | 2021-05-14 14:16:47.719 INFO 44 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
meetzicker | 2021-05-14 14:16:47.719 INFO 44 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 945 ms
meetzicker | 2021-05-14 14:16:47.811 WARN 44 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unsatisfied dependency expressed through method 'flywayInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingException: Cannot find migration scripts in: [classpath:db/migration] (please add migration scripts or check your Flyway configuration)
meetzicker | 2021-05-14 14:16:47.813 INFO 44 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
meetzicker | 2021-05-14 14:16:47.819 INFO 44 --- [ main] ConditionEvaluationReportLoggingListener :
meetzicker |
meetzicker | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
meetzicker | 2021-05-14 14:16:47.820 ERROR 44 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
meetzicker |
meetzicker | ***************************
meetzicker | APPLICATION FAILED TO START
meetzicker | ***************************
meetzicker |
meetzicker | Description:
meetzicker |
meetzicker | Flyway failed to initialize: none of the following migration scripts locations could be found:
meetzicker |
meetzicker | - classpath:db/migration
meetzicker |
meetzicker |
meetzicker | Action:
meetzicker |
meetzicker | Review the locations above or check your Flyway configuration
meetzicker |
meetzicker exited with code 1
meetzicker | wait-for-it.sh: waiting 15 seconds for db:5432
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
I removed orphans:
jules#jules-MS-7B51:~/Documents/MeetZicker/BACK/MeetZicker/MeetZicker/src/main/docker$ docker-compose up --remove-orphans
Removing orphan container "my-flyway"
Starting db ... done
Starting meetzicker ... done
Starting pgadmin4 ... done
Attaching to db, meetzicker, pgadmin4
db |
db | PostgreSQL Database directory appears to contain a database; Skipping initialization
db |
db | LOG: database system was interrupted; last known up at 2021-05-16 12:21:00 UTC
db | LOG: database system was not properly shut down; automatic recovery in progress
db | LOG: invalid record length at 0/14F1D38: wanted 24, got 0
db | LOG: redo is not required
meetzicker | wait-for-it.sh: waiting 15 seconds for db:5432
db | LOG: MultiXact member wraparound protections are now enabled
db | LOG: database system is ready to accept connections
db | LOG: autovacuum launcher started
pgadmin4 | [2021-05-17 11:09:31 +0000] [1] [INFO] Starting gunicorn 20.1.0
pgadmin4 | [2021-05-17 11:09:31 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmin4 | [2021-05-17 11:09:31 +0000] [1] [INFO] Using worker: threads
pgadmin4 | [2021-05-17 11:09:31 +0000] [83] [INFO] Booting worker with pid: 83
meetzicker | wait-for-it.sh: timeout occurred after waiting 15 seconds for db:5432
meetzicker |
meetzicker | . ____ _ __ _ _
meetzicker | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
meetzicker | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
meetzicker | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
meetzicker | ' |____| .__|_| |_|_| |_\__, | / / / /
meetzicker | =========|_|==============|___/=/_/_/_/
meetzicker | :: Spring Boot :: (v2.3.4.RELEASE)
meetzicker |
meetzicker | 2021-05-17 11:09:44.061 INFO 43 --- [ main] c.p.MeetZicker.MeetZickerApplication : Starting MeetZickerApplication v0.0.1-SNAPSHOT on d256a05b5f82 with PID 43 (/var/lib/meetzicker/meetzicker.jar started by root in /var/lib/meetzicker)
meetzicker | 2021-05-17 11:09:44.062 INFO 43 --- [ main] c.p.MeetZicker.MeetZickerApplication : The following profiles are active: dev
meetzicker | 2021-05-17 11:09:44.512 INFO 43 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
meetzicker | 2021-05-17 11:09:44.581 INFO 43 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 63ms. Found 12 JPA repository interfaces.
meetzicker | 2021-05-17 11:09:44.988 INFO 43 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
meetzicker | 2021-05-17 11:09:44.996 INFO 43 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
meetzicker | 2021-05-17 11:09:44.996 INFO 43 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
meetzicker | 2021-05-17 11:09:45.032 INFO 43 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
meetzicker | 2021-05-17 11:09:45.032 INFO 43 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 939 ms
meetzicker | 2021-05-17 11:09:45.123 WARN 43 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unsatisfied dependency expressed through method 'flywayInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingException: Cannot find migration scripts in: [classpath:db/migration] (please add migration scripts or check your Flyway configuration)
meetzicker | 2021-05-17 11:09:45.125 INFO 43 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
meetzicker | 2021-05-17 11:09:45.131 INFO 43 --- [ main] ConditionEvaluationReportLoggingListener :
meetzicker |
meetzicker | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
meetzicker | 2021-05-17 11:09:45.133 ERROR 43 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
meetzicker |
meetzicker | ***************************
meetzicker | APPLICATION FAILED TO START
meetzicker | ***************************
meetzicker |
meetzicker | Description:
meetzicker |
meetzicker | Flyway failed to initialize: none of the following migration scripts locations could be found:
meetzicker |
meetzicker | - classpath:db/migration
meetzicker |
meetzicker |
meetzicker | Action:
meetzicker |
meetzicker | Review the locations above or check your Flyway configuration
meetzicker |
Here is my public project:
https://github.com/praline40/MeetZickerAPI
Related
Is there a way to suspend java ( springboot ) unit tests execution when running mvn test and resume them later ?
So I have this test class :
#SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
class JavaAppApplicationTests {
#Test
void contextLoads() {}
#Test
#RepeatedTest(10)
public void testApplication() {
JavaAppApplication javaApp = new JavaAppApplication();
String result = javaApp.sanitize();
assertEquals(result, "{\"key1\":\"value1\",\"type\":\"Booking\",\"sid\":\"A435211\",\"region\":\"ASIA\",\"fetchFromFile\":\"false\",\"service\":\"true\",\"isEom\":\"true\"}");
}
}
And when I run mvn test, I see in the console logs the following :
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.6)
2022-05-17 11:00:29.481 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : Starting JavaAppApplicationTests using Java 17-internal on neo-VirtualBox with PID 58143 (started by neo in /home/neo/Desktop/spring-vulnerable-app)
2022-05-17 11:00:29.483 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : No active profile set, falling back to 1 default profile: "default"
2022-05-17 11:00:30.542 INFO 58143 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-17 11:00:30.561 INFO 58143 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-17 11:00:30.561 INFO 58143 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-05-17 11:00:30.749 INFO 58143 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-05-17 11:00:30.749 INFO 58143 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1230 ms
2022-05-17 11:00:31.497 INFO 58143 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-17 11:00:31.507 INFO 58143 --- [ main] c.e.javaapp.JavaAppApplicationTests : Started JavaAppApplicationTests in 2.452 seconds (JVM running for 3.887)
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4 s - in com.elastisys.javaapp.JavaAppApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
The JavaApplicationTests is started with a specific PID and a defined port and then tests are executed.
What I am looking for is a way to start the application and wait for a specific period before executing all the tests ( like it's suspended )
Thanks in advance
I try to connect spring app with postgresql.
When I run my app directly on server(not container), Connection success.
java -jar app.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-07-05 14:10:58.348 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : Starting PoemNoteApplication v1 using Java 11.0.11 on ip-172-31-3-67 with PID 334534 (/home/ubuntu/poemnote/poemNote/target/poemNote-1.jar started by ubuntu in /home/ubuntu/poemnote/poemNote)
2021-07-05 14:10:58.355 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : No active profile set, falling back to default profiles: default
2021-07-05 14:11:00.447 INFO 334534 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2021-07-05 14:11:00.498 INFO 334534 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 46 ms. Found 0 JDBC repository interfaces.
2021-07-05 14:11:01.903 INFO 334534 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2021-07-05 14:11:01.936 INFO 334534 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-05 14:11:01.936 INFO 334534 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-07-05 14:11:02.095 INFO 334534 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-05 14:11:02.095 INFO 334534 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3595 ms
2021-07-05 14:11:02.945 INFO 334534 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-07-05 14:11:03.197 INFO 334534 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-07-05 14:11:04.497 INFO 334534 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-05 14:11:04.762 INFO 334534 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2021-07-05 14:11:05.241 INFO 334534 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2021-07-05 14:11:05.267 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : Started PoemNoteApplication in 8.396 seconds (JVM running for 9.694)
^C2021-07-05 14:11:13.986 INFO 334534 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
But when i run container, connection fail like below
docker run -p port:port
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-07-05 14:12:37.130 INFO 1 --- [ main] com.studb.poemNote.PoemNoteApplication : Starting PoemNoteApplication v1 using Java 11.0.11 on de04c6a415a5 with PID 1 (/app/BOOT-INF/classes started by root in /app)
2021-07-05 14:12:37.139 INFO 1 --- [ main] com.studb.poemNote.PoemNoteApplication : No active profile set, falling back to default profiles: default
2021-07-05 14:12:38.997 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2021-07-05 14:12:39.055 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 0 JDBC repository interfaces.
2021-07-05 14:12:40.351 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2021-07-05 14:12:40.383 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-05 14:12:40.383 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-07-05 14:12:40.516 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-05 14:12:40.516 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3260 ms
2021-07-05 14:12:41.248 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-07-05 14:12:52.405 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.19.jar:42.2.19]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar:na]
It's my dockerfile
FROM adoptopenjdk:11-jre-hotspot as builder
WORKDIR app
ARG JAR_FILE=target/*jar
COPY ${JAR_FILE} app.jar
RUN java -Djarmode=layertools -jar app.jar extract
FROM adoptopenjdk:11-jre-hotspot
WORKDIR app
COPY --from=builder app/dependencies/ ./
COPY --from=builder app/spring-boot-loader/ ./
COPY --from=builder app/snapshot-dependencies/ ./
COPY --from=builder app/application/ ./
EXPOSE 9000
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
I can't understand why it does...
I try run container '--network host' but it's failed.
Postgresql running inside container on the same host
In case postgresql is also running inside a container of the same host, you need to make sure that they share the same network and that the containers can reach each other.
Check configured networks of the container:
docker inspect <container> -f "{{json .NetworkSettings.Networks }}"
Check if you can reach one container from the another:
docker exec -u 0 <container1> ping <container2> -c2
In case they are not on the same network, you need to create the network first and then connect the containers to it:
docker network create <network>
and
docker network connect <network> <container>
Postgresql running directly on the host
In case postgresql is running directly on the host where your docker container is running, you need to make sure that you can reach the host system from your container. Try to add the following command when you start the container
--add-host=host.docker.internal:host-gateway
Useful Links:
How to access host port from docker container
Docker : How to find the network my container is in?
https://docs.docker.com/network/
https://docs.docker.com/network/bridge/
I am trying to get a spring-boot application to run. However with my current settings I keep getting errors.
Java 8
Maven 3.6.1
Environment Variables checked
As of the new version 2.2.1 of spring-boot I keep getting the same error on closing the built-in tomcat.
I have a sample Spring-Boot Application which I can't seem to run properly. Took a clean version from spring initializr.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.547 s
[INFO] Finished at: 2019-11-07T22:28:54+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:run (default-cli) on project java13-app: Application finished with exit code: 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
When I go back to Spring 2.1.10 I get the following output.:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.10.RELEASE)
2019-11-07 22:38:33.194 INFO 2572 --- [ main] test.Application : Starting Application on DP-BTO-Tom with PID 2572 (Y:\tbrx\java-13-spring-boot\target\classes started by Tom in Y:\tbrx\java-13-spring-boot)
2019-11-07 22:38:33.196 INFO 2572 --- [ main] test.Application : No active profile set, falling back to default profiles: default
2019-11-07 22:38:33.966 INFO 2572 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-07 22:38:33.986 INFO 2572 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-07 22:38:33.986 INFO 2572 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-07 22:38:34.053 INFO 2572 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-07 22:38:34.054 INFO 2572 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 832 ms
2019-11-07 22:38:34.221 INFO 2572 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-07 22:38:34.361 INFO 2572 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-07 22:38:34.364 INFO 2572 --- [ main] test.Application : Started Application in 1.542 seconds (JVM running for 4.547)
2019-11-07 22:38:35.652 INFO 2572 --- [ Thread-5] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
[Terminate batch job (Y/N)? y
Instead of a build failure.
Asked, fixed and closed as a bug in Spring Boot - 2.2.1
https://github.com/spring-projects/spring-boot/issues/18936#event-2782909196
I have two small Spring Boot applications that exposes a rest API:
app-one
Get Request
- http://localhost:8010/api/stock/AAPL
Response:
{
"name": "AAPL",
"value": 219.9
}
app-two
Get Request
- http://localhost:8080/api/trade/APPL/buy/10
Response
{
"id": 1,
"stock": {
"name": "APPL",
"value": 219.9
},
"quantity": 10,
"total": 2199.0
}
When I run this two apps on my localhost without Docker I get the correct response from both APIs.
When I run the apps using the Docker Compose, the first API app-one responds OK, but the app-two returns an error:
"message": "I/O error on GET request for \"http://127.0.0.1:8010/api/stock/APPL\": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)",
"path": "/api/trade/APPL/buy/10"
This is my docker-compose.yml configuration file:
version: "3.7"
services:
app-one:
image: ibercode/app-one
ports:
- "8010:8010"
expose:
- "8010"
app-two:
build: .
ports:
- "8080:8080"
depends_on:
- app-one
environment:
- APP_ONE_URI=http://127.0.0.1:8010/api/stock/
And this is the output after I run the command docker-compose up
$ docker-compose up
Starting app-two_app-one_1 ... done
Starting app-two_app-two_1 ... done
Attaching to app-two_app-one_1, app-two_app-two_1
app-one_1 |
app-one_1 | . ____ _ __ _ _
app-one_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-one_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-one_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-one_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-one_1 | =========|_|==============|___/=/_/_/_/
app-one_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-one_1 |
app-one_1 | 2019-09-18 08:28:07.287 INFO 1 --- [ main] com.ibercode.AppOneApplication : Starting AppOneApplication vlatest on a090eb18a661 with PID 1 (/app.jar started by root in /)
app-one_1 | 2019-09-18 08:28:07.291 INFO 1 --- [ main] com.ibercode.AppOneApplication : No active profile set, falling back to default profiles: default
app-two_1 |
app-two_1 | . ____ _ __ _ _
app-two_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-two_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-two_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-two_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-two_1 | =========|_|==============|___/=/_/_/_/
app-two_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-two_1 |
app-two_1 | 2019-09-18 08:28:08.308 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Starting AppTwoApplication vlatest on 973897f9ea8d with PID 1 (/app.jar started by root in /)
app-two_1 | 2019-09-18 08:28:08.325 INFO 1 --- [ main] com.ibercode.AppTwoApplication : No active profile set, falling back to default profiles: default
app-one_1 | 2019-09-18 08:28:10.448 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)
app-one_1 | 2019-09-18 08:28:10.536 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-one_1 | 2019-09-18 08:28:10.537 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:10.731 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-one_1 | 2019-09-18 08:28:10.744 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3313 ms
app-one_1 | 2019-09-18 08:28:11.283 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:11.488 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:11.701 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''
app-one_1 | 2019-09-18 08:28:11.705 INFO 1 --- [ main] com.ibercode.AppOneApplication : Started AppOneApplication in 5.488 seconds (JVM running for 6.129)
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3281 ms
app-two_1 | 2019-09-18 08:28:12.077 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:12.249 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
app-two_1 | 2019-09-18 08:28:12.251 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Started AppTwoApplication in 5.016 seconds (JVM running for 5.955)
Any idea or suggestions?
Thanks
It seem you are trying to access app-1 from app-2 with the URL http://127.0.0.1:8010/api/stock/APPL. However you can't access the other container under 127.0.0.1 from another container.
You can access another service in the compose file by service name. That means, you need to configure your app-2 application to look for the host app-one, i.e. APP_ONE_URI=http://app-one/api/stock/.
You can read more about Compose networking here https://docs.docker.com/compose/networking/.
This question already has answers here:
Why does my Spring Boot App always shutdown immediately after starting?
(23 answers)
Closed 7 years ago.
Like the title said, I right click on the spring boot project and Run as Spring Boot App. This is what I saw in the Console window of STS:
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.2.RELEASE)
2016-01-30 21:06:29.124 INFO 6584 --- [ main] l.IssueManagerApplication : Starting IssueManagerApplication on LVN with PID 6584 (E:\_WORKSPACE\SPRING_BOOT\issue-manager\target\classes started by Le in E:\_WORKSPACE\SPRING_BOOT\issue-manager)
2016-01-30 21:06:29.130 INFO 6584 --- [ main] l.IssueManagerApplication : No active profile set, falling back to default profiles: default
2016-01-30 21:06:29.249 INFO 6584 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#12d575ec: startup date [Sat Jan 30 21:06:29 EET 2016]; root of context hierarchy
2016-01-30 21:06:31.208 INFO 6584 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-01-30 21:06:32.032 INFO 6584 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-30 21:06:32.077 INFO 6584 --- [ main] l.IssueManagerApplication : Started IssueManagerApplication in 4.163 seconds (JVM running for 6.548)
2016-01-30 21:06:32.078 INFO 6584 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#12d575ec: startup date [Sat Jan 30 21:06:29 EET 2016]; root of context hierarchy
2016-01-30 21:06:32.084 INFO 6584 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
And when I open localhost:8080, it just displayed a grey page saying "This webpage is not available". Apparently the server does not start at all or it started but then stopped right after that.
I already tried run mvn spring-boot:run, it also log out information as above plus BUILD SUCCESS and stops even without me Ctrl + C. So I dont know how to run my "hello world" spring-boot application.
I resolved the issue by adding this in my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Thanks to this post:
Why my Spring Boot App always shutdown