No ServletContext set. Problem with connection to DB in another container - spring-boot

I have Kotlin pet-project with docker-compose file:
version: '3.1'
services:
app:
build:
context: .
dockerfile: Dockerfile
command: java -jar ./testapp.jar
ports:
- "8080:8080"
depends_on:
- postgres
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://172.25.1.3:5432/kotlin-app
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=Tolstochok3000
networks:
app-network:
ipv4_address: 172.25.1.2
postgres:
build:
context: docker/db
dockerfile: Dockerfile
command: postgres
environment:
POSTGRES_DB: "kotlin-app"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "Tolstochok3000"
ports:
- "5432:5432"
networks:
app-network:
ipv4_address: 172.25.1.3
restart: always
networks:
app-network:
ipam:
config:
- subnet: 172.25.1.0/16
I tried docker-compose up, postgres started without problem, but app throw exception: Factory method 'resourceHandlerMapping' threw exception;
nested exception is java.lang.IllegalStateException: No ServletContext set
When I started application on localhost (without docker), application work correctly with db in docker.
Application dockerfile:
FROM gradle:jdk17 as builder
WORKDIR /test-kotlin-app
COPY src ./src
COPY build.gradle.kts ./build.gradle.kts
RUN gradle clean build
FROM openjdk:17-alpine as backend
WORKDIR /root
COPY --from=builder /test-kotlin-app/build/libs/* ./app
ENTRYPOINT ["java", "-jar", "/root/app"]
Application propeties:
#DATABSE SETTINGS
datasource:
driver-class-name: org.postgresql.Driver
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/kotlin-app}
username: ${SPRING_DATASOURCE_USERNAME:postgres}
password: ${SPRING_DATASOURCE_PASSWORD:Tolstochok3000}
#JPA SETTINGS
jpa:
show-sql: 'true'
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
I tried change docker-compose file application.yml (remove variables) and try remove network, but it didn't help
Error: java.lang.IllegalStateException: No ServletContext set
stacktrace:
test_kotlin_app-app-1 | 08:01:35.023 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Before shutdown stats (total=10, active=0, idle=10, waiting=0)
test_kotlin_app-app-1 | 08:01:35.029 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#2db15f70: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#6d2041d5: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#22daa83a: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#3599b284: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#42f55775: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#54a28df5: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#5668d8b3: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.030 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#2e9d5d68: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.031 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#46bbe931: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.031 [HikariPool-1 connection closer] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Closing connection org.postgresql.jdbc.PgConnection#6b60936: (connection evicted)
test_kotlin_app-app-1 | 08:01:35.032 [main] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - After shutdown stats (total=0, active=0, idle=0, waiting=0)
test_kotlin_app-app-1 | 08:01:35.032 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
test_kotlin_app-app-1 | 08:01:35.035 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
test_kotlin_app-app-1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/W
ebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.se
rvlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
test_kotlin_app-app-1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
test_kotlin_app-app-1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
test_kotlin_app-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
test_kotlin_app-app-1 | at ru.rsu.app.KotlinAppApplicationKt.main(KotlinAppApplication.kt:13)
test_kotlin_app-app-1 | Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; ne
sted exception is java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
test_kotlin_app-app-1 | ... 18 common frames omitted
test_kotlin_app-app-1 | Caused by: java.lang.IllegalStateException: No ServletContext set
test_kotlin_app-app-1 | at org.springframework.util.Assert.state(Assert.java:76)
test_kotlin_app-app-1 | at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:591)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
test_kotlin_app-app-1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
test_kotlin_app-app-1 | at java.base/java.lang.reflect.Method.invoke(Method.java:568)
test_kotlin_app-app-1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
test_kotlin_app-app-1 | ... 19 common frames omitted

I resolve problem, when fixed build section in build.gradle.kts file. Remove block tasks.withType and add build section with default spring boot builder:
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
mainClass.set("con.example.app.KotlinAppApplicationKt")
archiveBaseName.set("testapp")
archiveFileName.set("testapp.jar") }

Perhaps your DB container is not yet ready when the app is initialized. You may want to implement some waiting mechanism like this or like some of the solutions here.

Related

Spring Boot - Rabbitmq java.net.ConnectException: Connection refused

I have been working on a banking project. I have a problem that is about RabbitMQ and Docker.
I have two microservices that are called query and command. Both of them can not connect to my RabbitMq container. I have been trying to solve this problem, but I could not.
I can succesfully connect and open http://localhost:15672/#/ after docker compose.
When I run docker compose up, account-cmd and account-query services not running on the browser. Here is my docker-compose.yml file.
version: "3.4"
services:
customerdb:
container_name: customerdb
image: postgres
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
volumes:
- ./customer/postgres_init.sql:/docker-entrypoint-initdb.d/postgres_init.sql
ports:
- "5432:5432"
restart: unless-stopped
querydb:
container_name: querydb
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
volumes:
- ./account.query/postgres_init.sql:/docker-entrypoint-initdb.d/postgres_init.sql
ports:
- "5433:5432"
restart: unless-stopped
rabbitmq:
container_name: "bank_rabbitmq"
image: "rabbitmq:3.8-management"
hostname: "rabbitmq"
environment:
RABBITMQ_DEFAULT_USER: "guest"
RABBITMQ_DEFAULT_PASS: "guest"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "15672:15672"
- "5672:5672"
cmddb:
container_name: "cmddb"
image: mongo
restart: always
ports:
- "27017:27017"
customer-service:
image: bank/customer-service-api
container_name: customer-service
build:
context: ./customer
dockerfile: Dockerfile
ports:
- "5000:5000"
depends_on:
- customerdb
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://customerdb:5432/customerdb
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
account-cmd:
image: bank/account-cmd-service-api
container_name: account-cmd-service
build:
context: ./account.cmd
dockerfile: Dockerfile
ports:
- "5002:5002"
depends_on:
- cmddb
- rabbitmq
environment:
- SPRING_DATA_MONGODB_HOST=cmddb
- SPRING_DATA_MONGODB_PORT=27017
- SPRING_DATA_MONGODB_DATABASE=accountcmdb
- SPRING_RABBITMQ_HOST=rabbitmq
- SPRING_RABBITMQ_PORT=5672
- SPRING_RABBITMQ_USERNAME=guest
- SPRING_RABBITMQ_PASSWORD=guest
account-query:
image: bank/account-query-service-api
container_name: account-query-service
build:
context: ./account.query
dockerfile: Dockerfile
ports:
- "5003:5003"
depends_on:
- querydb
- rabbitmq
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://querydb:5433/accountingdb
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=postgres
- SPRING_RABBITMQ_HOST=rabbitmq
- SPRING_RABBITMQ_PORT=5672
- SPRING_RABBITMQ_USERNAME=guest
- SPRING_RABBITMQ_PASSWORD=guest
volumes:
customerdb:
cmddb:
querydb:
Here is my RabbitMQConfig on spring boot.
package com.bankingsolution.account.query.configuration;
import com.bankingsolution.common.constants.Contants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
import java.util.Arrays;
import java.util.List;
#Configuration
public class RabbitMQConfig implements RabbitListenerConfigurer {
#Value("${spring.rabbitmq.host}")
private String hostName;
#Value("${spring.rabbitmq.username}")
private String userName;
#Value("${spring.rabbitmq.password}")
private String password;
#Value("${spring.rabbitmq.port}")
private int port;
#Bean
public TopicExchange exchange() {
return new TopicExchange(Contants.TOPIC_KEY);
}
#Bean
Queue accountOpenedQueue() {
return new Queue(Contants.AccountOpenedTopic);
}
#Bean
Queue fundsDepositedQueue() {
return new Queue(Contants.FundsDepositedTopic);
}
#Bean
Queue fundsWithdrawnQueue() {
return new Queue(Contants.FundsWithDrawnTopic);
}
#Bean
Queue transactionCreatedQueue() {
return new Queue(Contants.TransactionCreatedTopic);
}
#Bean
Queue transactionFailedQueue() {
return new Queue(Contants.TransactionFailedTopic);
}
#Bean
public List<Binding> binding() {
return Arrays.asList(
BindingBuilder.bind(accountOpenedQueue()).to(exchange()).with(Contants.AccountOpenedTopic),
BindingBuilder.bind(fundsDepositedQueue()).to(exchange()).with(Contants.FundsDepositedTopic),
BindingBuilder.bind(fundsWithdrawnQueue()).to(exchange()).with(Contants.FundsWithDrawnTopic),
BindingBuilder.bind(transactionCreatedQueue()).to(exchange()).with(Contants.TransactionCreatedTopic),
BindingBuilder.bind(transactionFailedQueue()).to(exchange()).with(Contants.TransactionFailedTopic));
}
#Bean
public MessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
#Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
return factory;
}
#Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(this.hostName);
connectionFactory.setVirtualHost("/");
connectionFactory.setUsername(this.userName);
connectionFactory.setPassword(this.password);
connectionFactory.setPort(this.port);
return connectionFactory;
}
#Override
public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {
registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());
}
#Bean
public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
factory.setMessageConverter(new MappingJackson2MessageConverter());
return factory;
}
}
Here is sample error on Docker for a microservice.
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:463) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:447) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1925) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1906) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1349) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(Unknown Source) ~[na:na]
at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.13.1.jar!/:5.13.1]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1223) ~[amqp-client-5.13.1.jar!/:5.13.1]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1173) ~[amqp-client-5.13.1.jar!/:5.13.1]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
... 12 common frames omitted
2022-03-22 01:07:40.006 INFO 1 --- [ntContainer#4-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [rabbitmq:5672]
2022-03-22 01:07:40.006 INFO 1 --- [ntContainer#4-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [rabbitmq:5672]
2022-03-22 01:07:40.007 ERROR 1 --- [ntContainer#4-2] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2175) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2148) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2128) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:463) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:447) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1925) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1906) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1349) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1195) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(Unknown Source) ~[na:na]
at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.13.1.jar!/:5.13.1]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1223) ~[amqp-client-5.13.1.jar!/:5.13.1]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1173) ~[amqp-client-5.13.1.jar!/:5.13.1]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ~[spring-rabbit-2.4.2.jar!/:2.4.2]
... 12 common frames omitted
2022-03-22 01:07:40.008 INFO 1 --- [ntContainer#4-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [rabbitmq:5672]
2022-03-22 01:07:40.023 INFO 1 --- [ main] c.b.account.query.QueryApplication : Started QueryApplication in 8.535 seconds (JVM running for 9.399)
2022-03-22 01:07:44.965 WARN 1 --- [ntContainer#0-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.965 WARN 1 --- [ntContainer#0-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.966 WARN 1 --- [ntContainer#0-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.966 WARN 1 --- [ntContainer#0-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.969 INFO 1 --- [ntContainer#0-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#27755487: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.969 INFO 1 --- [ntContainer#0-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#2e5b7fba: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.969 INFO 1 --- [ntContainer#0-4] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#4f0cab0a: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.969 INFO 1 --- [ntContainer#0-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#60d40ff4: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.970 INFO 1 --- [ntContainer#0-5] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [rabbitmq:5672]
2022-03-22 01:07:44.971 WARN 1 --- [ntContainer#1-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.971 INFO 1 --- [ntContainer#1-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#6fc6deb7: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.973 WARN 1 --- [ntContainer#1-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.973 INFO 1 --- [ntContainer#1-4] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#7da39774: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.976 WARN 1 --- [ntContainer#1-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.979 INFO 1 --- [ntContainer#1-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#367f0121: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.979 WARN 1 --- [ntContainer#1-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.979 INFO 1 --- [ntContainer#1-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#441b8382: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.982 WARN 1 --- [ntContainer#2-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.982 INFO 1 --- [ntContainer#2-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#39bbd9e0: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.984 WARN 1 --- [ntContainer#2-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.984 INFO 1 --- [ntContainer#2-4] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#4397a639: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.986 WARN 1 --- [ntContainer#2-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.986 INFO 1 --- [ntContainer#2-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#27fe9713: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.988 WARN 1 --- [ntContainer#2-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.988 INFO 1 --- [ntContainer#2-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#11c3ff67: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.994 WARN 1 --- [ntContainer#3-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.999 WARN 1 --- [ntContainer#3-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.999 WARN 1 --- [ntContainer#3-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:44.999 INFO 1 --- [ntContainer#3-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#3e4e4c1: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.999 INFO 1 --- [ntContainer#3-4] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#46a488c2: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:44.999 INFO 1 --- [ntContainer#3-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#3ae126d1: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.000 WARN 1 --- [ntContainer#3-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:45.000 INFO 1 --- [ntContainer#3-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#7e7f3cfd: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.004 WARN 1 --- [ntContainer#4-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:45.005 INFO 1 --- [ntContainer#4-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#49d831c2: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.008 WARN 1 --- [ntContainer#4-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:45.009 INFO 1 --- [ntContainer#4-4] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#28bdbe88: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.010 WARN 1 --- [ntContainer#4-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:45.010 INFO 1 --- [ntContainer#4-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#43fda8d9: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.011 WARN 1 --- [ntContainer#4-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2022-03-22 01:07:45.011 INFO 1 --- [ntContainer#4-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#53a7a60c: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2022-03-22 01:07:45.038 INFO 1 --- [ntContainer#0-5] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#51abf713:45/SimpleConnection#427bde5e [delegate=amqp://rabbitmq#172.23.0.5:5672/, localPort= 54968]
I would be very happy if someone could help.
Here is my github repository.
https://github.com/dogaanismail/bank-solution

After a few days, the Java application stops working

I am writing a pet application in Java. Spring database Web.
I place all this on the server in separate docker containers.
The database is created in the docker-compose file
postgres-content:
image: postgres:14.1
container_name: content_db-v01
restart: unless-stopped
ports:
- "5532:5432"
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=*****
volumes:
- /home/my-db/content_db:/var/first-prj/data/content
- ./sql/create_db_catalog.sql:/docker-entrypoint-initdb.d/create_db_catalog.sql
I use liquibase to create a table. To work with the JPA database.
spring:
jpa.properties.hibernate.jdbc.lob.non_contextual_creation: true
jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
jpa:
show-sql: true
hibernate:
ddl-auto: none
datasource:
initialization-mode: always
driver-class-name: org.postgresql.Driver
jdbc-url: jdbc:postgresql://postgres-content:5432/catalog_content?currentSchema=catalog&stringtype=unspecified
username: content
password: *****
liquibase:
enabled: true
change-log: classpath:db/changelog/db.changelog.xml
Everything works fine. I launch it, I check what I wrote for a day or two. But a few days pass, I connect to the server to download a new version. And my application is constantly overloaded.
Just restarting containers doesn't help.
I'm deleting the directory from the database on the server. I overload and everything works again.
The first time I thought it was an accident. But this happened the second time.
Tell me where and how to find a solution to this problem?
Where to look?
Here's what he writes in the logs:
19-01-2022 07:41:33.921 [main] INFO ru.home.marketplace.contentservice.ContentServiceApplication.logStarting - Starting ContentServiceApplication v1.0-SNAPSHOT using Java 14.0.2 on c8abc4b4ef14 with PID 1 (/content.jar started by root in /)
content-v01 | 19-01-2022 07:41:33.926 [main] INFO ru.home.marketplace.contentservice.ContentServiceApplication.logStartupProfileInfo - No active profile set, falling back to default profiles: default
content-v01 | 19-01-2022 07:41:35.696 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
content-v01 | 19-01-2022 07:41:35.872 [main] INFO org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn - Finished Spring Data repository scanning in 156 ms. Found 7 JPA repository interfaces.
content-v01 | 19-01-2022 07:41:36.710 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize - Tomcat initialized with port(s): 9005 (http)
content-v01 | 19-01-2022 07:41:36.730 [main] INFO org.apache.catalina.core.StandardService.log - Starting service [Tomcat]
content-v01 | 19-01-2022 07:41:36.730 [main] INFO org.apache.catalina.core.StandardEngine.log - Starting Servlet engine: [Apache Tomcat/9.0.54]
content-v01 | 19-01-2022 07:41:36.820 [main] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/content].log - Initializing Spring embedded WebApplicationContext
content-v01 | 19-01-2022 07:41:36.820 [main] INFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.prepareWebApplicationContext - Root WebApplicationContext: initialization completed in 2785 ms
content-v01 | 19-01-2022 07:41:37.014 [main] INFO com.zaxxer.hikari.HikariDataSource.getConnection - HikariPool-1 - Starting...
content-v01 | 19-01-2022 07:41:38.138 [main] ERROR com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException - HikariPool-1 - Exception during pool initialization.
content-v01 | org.postgresql.util.PSQLException: The connection attempt failed.
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
content-v01 | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
content-v01 | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
content-v01 | at org.postgresql.Driver.makeConnection(Driver.java:465)
content-v01 | at org.postgresql.Driver.connect(Driver.java:264)
content-v01 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
content-v01 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
content-v01 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
content-v01 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
content-v01 | at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:313)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
content-v01 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
content-v01 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
content-v01 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:771)
content-v01 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:763)
content-v01 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318)
content-v01 | at ru.home.marketplace.contentservice.ContentServiceApplication.main(ContentServiceApplication.java:11)
content-v01 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
content-v01 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
content-v01 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
content-v01 | at java.base/java.lang.reflect.Method.invoke(Method.java:564)
content-v01 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
content-v01 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
content-v01 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
content-v01 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
content-v01 | Caused by: java.net.UnknownHostException: postgres-content
content-v01 | at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567)
content-v01 | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
content-v01 | at java.base/java.net.Socket.connect(Socket.java:648)
content-v01 | at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
content-v01 | at org.postgresql.core.PGStream.<init>(PGStream.java:95)
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
content-v01 | ... 41 common frames omitted
content-v01 | 19-01-2022 07:41:38.140 [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.refresh - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: The connection attempt failed.
content-v01 | 19-01-2022 07:41:38.146 [main] INFO org.apache.catalina.core.StandardService.log - Stopping service [Tomcat]
content-v01 | 19-01-2022 07:41:38.162 [main] INFO org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.logMessage -
content-v01 |
content-v01 | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
content-v01 | 19-01-2022 07:41:38.184 [main] ERROR org.springframework.boot.SpringApplication.reportFailure - Application run failed
content-v01 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: The connection attempt failed.
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
content-v01 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
content-v01 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908)
content-v01 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
content-v01 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
content-v01 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:771)
content-v01 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:763)
content-v01 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
content-v01 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318)
content-v01 | at ru.home.marketplace.contentservice.ContentServiceApplication.main(ContentServiceApplication.java:11)
content-v01 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
content-v01 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
content-v01 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
content-v01 | at java.base/java.lang.reflect.Method.invoke(Method.java:564)
content-v01 | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
content-v01 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
content-v01 | at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
content-v01 | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
content-v01 | Caused by: liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: The connection attempt failed.
content-v01 | at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:318)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
content-v01 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
content-v01 | ... 27 common frames omitted
content-v01 | Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
content-v01 | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
content-v01 | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
content-v01 | at org.postgresql.Driver.makeConnection(Driver.java:465)
content-v01 | at org.postgresql.Driver.connect(Driver.java:264)
content-v01 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
content-v01 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
content-v01 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560)
content-v01 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
content-v01 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
content-v01 | at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:313)
content-v01 | ... 29 common frames omitted
content-v01 | Caused by: java.net.UnknownHostException: postgres-content
content-v01 | at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567)
content-v01 | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
content-v01 | at java.base/java.net.Socket.connect(Socket.java:648)
content-v01 | at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
content-v01 | at org.postgresql.core.PGStream.<init>(PGStream.java:95)
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
content-v01 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
content-v01 | ... 41 common frames omitted
content-v01 exited with code 1
The database container is unavailable. But why did this happen? And where to look for the error?
Here are the logs of the container with the database after restarting the container. I didn't think to look before restarting.
2022-01-19 07:39:17.471 UTC [1] LOG: starting PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-01-19 07:39:17.473 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-01-19 07:39:17.473 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-01-19 07:39:17.600 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-01-19 07:39:17.681 UTC [64] LOG: database system was shut down at 2022-01-19 07:39:17 UTC
2022-01-19 07:39:17.721 UTC [1] LOG: database system is ready to accept connections
2022-01-19 07:42:00.441 UTC [1] LOG: received fast shutdown request
2022-01-19 07:42:00.446 UTC [1] LOG: aborting any active transactions
2022-01-19 07:42:00.450 UTC [1] LOG: background worker "logical replication launcher" (PID 70) exited with exit code 1
2022-01-19 07:42:00.454 UTC [65] LOG: shutting down
2022-01-19 07:42:00.546 UTC [1] LOG: database system is shut down
Have you tried running it using the same network?
Add your network to your services named postgres-content and spring.
networks:
- app-network
Finally, create your network definition at the bottom of your docker-compose.yml file.
networks:
app-network:
name: app-network

Spring Boot with ElasticSearch in Groovy: WebClient not present Exception

I am running a small demo spring-boot application where I want to connect my url routes with elasticsearch queries. The app starts up just fine with those gradle dependencies:
implementation('org.springframework.data:spring-data-elasticsearch')
implementation('org.elasticsearch:elasticsearch')
implementation('org.elasticsearch.client:elasticsearch-rest-high-level-client')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.codehaus.groovy:groovy')
As soon as I add the class ElasticsearchClientConfig (not yet used by me, just loaded):
package me.spring.GroovyDemo.store
import me.spring.GroovyDemo.AppConstants
import org.elasticsearch.client.RestHighLevelClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.elasticsearch.client.ClientConfiguration
import org.springframework.data.elasticsearch.client.RestClients
import org.springframework.data.elasticsearch.core.ElasticsearchOperations
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
#Configuration
#EnableElasticsearchRepositories(basePackages = "me.spring.GroovyDemo")
#ComponentScan(basePackages = ["me.spring.GroovyDemo"])
class ElasticsearchClientConfig {
#Bean
RestHighLevelClient client() {
ClientConfiguration clientConfiguration
= ClientConfiguration.builder()
.connectedTo(AppConstants.ELASTIC_SERVER)
.build()
return RestClients.create(clientConfiguration).rest()
}
#Bean
ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchRestTemplate(client())
}
}
The app fails on startup.
I found many similar issues. But none of them seems to fail with missing Webclient. I don't really get that I would need a WebClient in the first place.
The exception is as follows:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.0)
2021-05-27 12:02:32.598 INFO 4462 --- [ main] m.s.GroovyDemo.GroovyDemoApplication : Starting GroovyDemoApplication using Java 1.8.0_292 on vagrant-VirtualBox with PID 4462 (/home/vagrant/GroovyOpenApi/out/production/classes started by vagrant in /home/vagrant/GroovyOpenApi)
2021-05-27 12:02:32.600 INFO 4462 --- [ main] m.s.GroovyDemo.GroovyDemoApplication : No active profile set, falling back to default profiles: default
2021-05-27 12:02:32.890 WARN 4462 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2021-05-27 12:02:33.230 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2021-05-27 12:02:33.240 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6 ms. Found 0 Elasticsearch repository interfaces.
2021-05-27 12:02:33.402 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
2021-05-27 12:02:33.404 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1 ms. Found 0 Elasticsearch repository interfaces.
2021-05-27 12:02:33.407 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
2021-05-27 12:02:33.409 INFO 4462 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1 ms. Found 0 Reactive Elasticsearch repository interfaces.
2021-05-27 12:02:33.799 INFO 4462 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-27 12:02:33.807 INFO 4462 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-27 12:02:33.807 INFO 4462 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-05-27 12:02:33.861 INFO 4462 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-27 12:02:33.861 INFO 4462 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1065 ms
2021-05-27 12:02:34.035 WARN 4462 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [me/spring/GroovyDemo/store/ElasticsearchClientConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'client' threw exception; nested exception is java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
2021-05-27 12:02:34.038 INFO 4462 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-05-27 12:02:34.054 INFO 4462 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-05-27 12:02:34.078 ERROR 4462 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [me/spring/GroovyDemo/store/ElasticsearchClientConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'client' threw exception; nested exception is java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.7.jar:5.3.7]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.7.jar:5.3.7]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438) [spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:337) [spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) [spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325) [spring-boot-2.5.0.jar:2.5.0]
at org.springframework.boot.SpringApplication$run.call(Unknown Source) [spring-boot-2.5.0.jar:2.5.0]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148) [groovy-3.0.8.jar:3.0.8]
at me.spring.GroovyDemo.GroovyDemoApplication.main(GroovyDemoApplication.groovy:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'client' threw exception; nested exception is java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.7.jar:5.3.7]
... 23 common frames omitted
Caused by: java.lang.TypeNotPresentException: Type org.springframework.web.reactive.function.client.WebClient not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:1.8.0_292]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:1.8.0_292]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_292]
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:1.8.0_292]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:1.8.0_292]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_292]
at sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository.java:68) ~[na:1.8.0_292]
at java.lang.reflect.Method.getGenericReturnType(Method.java:255) ~[na:1.8.0_292]
at java.beans.FeatureDescriptor.getReturnType(FeatureDescriptor.java:370) ~[na:1.8.0_292]
at java.beans.Introspector.getTargetEventInfo(Introspector.java:1052) ~[na:1.8.0_292]
at java.beans.Introspector.getBeanInfo(Introspector.java:427) ~[na:1.8.0_292]
at java.beans.Introspector.getBeanInfo(Introspector.java:173) ~[na:1.8.0_292]
at groovy.lang.MetaClassImpl.lambda$addProperties$4(MetaClassImpl.java:3460) ~[groovy-3.0.8.jar:3.0.8]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_292]
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3460) ~[groovy-3.0.8.jar:3.0.8]
at groovy.lang.MetaClassImpl.reinitialize(MetaClassImpl.java:3442) ~[groovy-3.0.8.jar:3.0.8]
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3435) ~[groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:273) ~[groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:315) ~[groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:258) ~[groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:987) ~[groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:71) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:156) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) [groovy-3.0.8.jar:3.0.8]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130) [groovy-3.0.8.jar:3.0.8]
at me.spring.GroovyDemo.store.ElasticsearchClientConfig.client(ElasticsearchClientConfig.groovy:21) ~[classes/:na]
at me.spring.GroovyDemo.store.ElasticsearchClientConfig$$EnhancerBySpringCGLIB$$a214165c.CGLIB$client$0(<generated>) ~[classes/:na]
at me.spring.GroovyDemo.store.ElasticsearchClientConfig$$EnhancerBySpringCGLIB$$a214165c$$FastClassBySpringCGLIB$$c29866d5.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.7.jar:5.3.7]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.7.jar:5.3.7]
at me.spring.GroovyDemo.store.ElasticsearchClientConfig$$EnhancerBySpringCGLIB$$a214165c.client(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_292]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_292]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_292]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_292]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.7.jar:5.3.7]
... 24 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.web.reactive.function.client.WebClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_292]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_292]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) ~[na:1.8.0_292]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_292]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_292]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_292]
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:1.8.0_292]
... 60 common frames omitted
Process finished with exit code 1
Somehow I am not able to create the ES client bean.
My App is in package me.spring.GroovyDemo, everything else is below.
I tried adding some dependencies, like webflux to get WebClient, but did not really help.
What is the reason for the failing startup?
I got your example running by adding
implementation('org.springframework:spring-webflux')
Where does this reference to the WebClient class come from? Spring Data Elasticsearch is built with an optional dependency to org.springframework:spring-webflux because it contains code for both the imperative and the reactive setup. Optional because we need it to build the library, but you do not need it when running - in imperative mode.
Now the ClientConfiguration class and its builder have a method withWebClientConfigurer(Function<WebClient, WebClient> webClientConfigurer). This function is compiled into the library.
When running an imperative, non-reactive application which does not have webflux in it's classpath in Java or Kotlin everything is fine - the application itself was never compiled to use this function and so it is not needed and the transitive optional dependency is never resolved. It does not matter if these optional dependencies are in the loaded class as long as they are not used - otherwise the compiler would have complained.
In Groovy this seems to be different. Here there is some Java-bean inspection running on the ClientConfiguration class which finds the afore mentioned method but cannot find the WebClient class, because that's not on the classpath.
So by adding the dependency to the classpath this error goes away by the cost of having a library with reactive code in the classpath - now some Spring Boot austoconfiguration could be tempted to pick something up from there.
I don't know what would be a better solution, or if groovy can handle optional dependencies better, I'm not using groovy. Someone with more insights might have a better answer.
From the stacktrace follows that you should add a missing dependency to spring-web-reactive to your Gradle config:
dependencies {
//...
implementation 'org.springframework:spring-web-reactive:5.0.0.M4'
}

IllegalStateException: Topic(s) [XYZ] is/are not present and missingTopicsFatal is true

I have a Spring Boot app that tries to read from a local Kafka topic.
The app starts to spin up, pauses for 2 minutes and throws the following error:
19-11-10 14:49:24.700 INFO 20476 --- [ restartedMain] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1573390164696
2019-11-10 14:51:24.793 WARN 20476 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is java.lang.IllegalStateException: Topic(s) [XYZ] is/are not present and missingTopicsFatal is true
2019-11-10 14:51:24.795 INFO 20476 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
2019-11-10 14:51:24.796 INFO 20476 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2019-11-10 14:51:24.810 INFO 20476 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-11-10 14:51:24.837 INFO 20476 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-10 14:51:24.844 ERROR 20476 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is java.lang.IllegalStateException: Topic(s) [XYZ] is/are not present and missingTopicsFatal is true
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at com.example.main(NyApplication.java:38) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]
Caused by: java.lang.IllegalStateException: Topic(s) [ZYX] is/are not present and missingTopicsFatal is true
at org.springframework.kafka.listener.AbstractMessageListenerContainer.checkTopics(AbstractMessageListenerContainer.java:366) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.kafka.listener.ConcurrentMessageListenerContainer.doStart(ConcurrentMessageListenerContainer.java:136) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.kafka.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:323) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistry.startIfNecessary(KafkaListenerEndpointRegistry.java:309) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistry.start(KafkaListenerEndpointRegistry.java:256) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 19 common frames omitted `
The kafka runs in a docker on the local computer:
docker run --detach --name kafka -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=192.168.1.89 --env ADVERVTISED_PORT=9092 --env AUTO.CREATE.TOPICS.ENABLE spotify/kafka
When bash into the container
docker exec -it 1234567896b5 bash
I can see the topic:
$/opt/kafka_2.11-0.10.1.0/bin# ./kafka-topics.sh --list --zookeeper localhost:2181
$XYZ
The topic was created with this command:
./kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 1 --partitions 3 --topic XYZ
And I have this in the application.yml of the app (also tried with port 9092):
spring:
kafka:
consumer:
bootstrap-servers: localhost:2181
group-id: group_id
auto-offset-reset: earliest
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
producer:
bootstrap-servers: localhost:2181
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
set spring.kafka.listener.missing-topics-fatal=false
on your application.yml or application.properties
Your config is using Zookeeper, not Kafka as the bootstrap servers
Use port 9092, not 2181
Also, that Spotify container is not maintained, so I suggest finding a newer one
This may not be the answer to the question, but I'm putting this so it can be helpful to someone else.
I faced the same exception even when I used the appropriate port number in the config (9092)
Here's the stacktrace.
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
....
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is java.lang.IllegalStateException: Topic(s) [my-cute-topic] is/are not present and missingTopicsFatal is true
The Solution
I just created the topic in my local kafka and it worked fine.
This might help someone in the future. I am trying to address this error Topic(s) [yourTopicName] is/are not present and missingTopicsFatal is true.
You might need to add a bean in your configuration. I had this error and this was my solution - adding a bean of NewTopic.
#Bean
public NewTopic adviceTopic() {
return new NewTopic("user", 3, this.replicationFactor);
}
The yml alternative of the previous answer is:
spring:
kafka:
listener:
missing-topics-fatal: false

IntelliJ throwing errors when running spring boot application but not when running from terminal?

I'm wanting to run my spring-boot application from intelliJ instead of using the terminal, but it won't let me, it just throws a whole heap of errors, whereas when I run mvn spring-boot:run from the terminal inside intelliJ, the application starts as expected.
Stack trace:
When running via intelliJ (the run button in the top right corner):
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.5.RELEASE)
2016-06-16 17:41:37.783 INFO 7968 --- [ restartedMain] spring.Application : Starting Application on JamesWMAC.local with PID 7968 (/Users/james/IdeaProjects/myProject/target/classes started by james in /Users/james/IdeaProjects/myProject)
2016-06-16 17:41:37.786 INFO 7968 --- [ restartedMain] spring.Application : No active profile set, falling back to default profiles: default
2016-06-16 17:41:37.863 INFO 7968 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4a81556: startup date [Thu Jun 16 17:41:37 EST 2016]; root of context hierarchy
2016-06-16 17:41:39.263 INFO 7968 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e89ecf20] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-06-16 17:41:39.604 INFO 7968 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-06-16 17:41:39.621 INFO 7968 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-06-16 17:41:39.622 INFO 7968 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-06-16 17:41:39.697 INFO 7968 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-06-16 17:41:39.697 INFO 7968 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1838 ms
2016-06-16 17:41:39.889 INFO 7968 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-06-16 17:41:39.892 INFO 7968 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-06-16 17:41:39.892 INFO 7968 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-06-16 17:41:39.892 INFO 7968 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-06-16 17:41:39.892 INFO 7968 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-06-16 17:41:40.157 INFO 7968 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-06-16 17:41:40.163 INFO 7968 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-06-16 17:41:40.167 WARN 7968 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
2016-06-16 17:41:40.172 INFO 7968 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service Tomcat
2016-06-16 17:41:40.182 ERROR 7968 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
at spring.Application.main(Application.java:47) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.3.5.RELEASE.jar:1.3.5.RELEASE]
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_05]
at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_05]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_05]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[na:1.8.0_05]
at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_05]
at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[na:1.8.0_05]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_05]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_05]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_05]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_05]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_05]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildBootstrapServiceRegistry(EntityManagerFactoryBuilderImpl.java:486) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:208) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) ~[spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319) ~[spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 21 common frames omitted
2016-06-16 17:41:40.183 INFO 7968 --- [ restartedMain] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/Users/james/IdeaProjects/myProject/target/classes/]
But when I go and run:
mvn spring-boot:run
In the terminal, my app starts and I can start making http calls to the server.
I know it's not in time =) But I just solved same trouble and in my case, it solved when I update Maven dependency from IntelliJ.
IntelliJ IDEA is not using the same classpath for some reason. See What causes java.lang.IncompatibleClassChangeError?. If you have a manual setup I'd review that in the IDE. You may also have conflicting libraries in your classpath and it works from the terminal "by chance".

Resources