Spring Cloud Gateway Resilience4j specific Circuit Breaker assigned to a route - spring-cloud

Spring Cloud 2020.0.3
Attempting to configure reactive circuit breakers per defined route. However, I always get the default circuit breaker properties rather than the specific auth-service instance properties.
POM:
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
<jersey-apache-client4.ver>1.19.4</jersey-apache-client4.ver>
<resilience4j-spring-boot2.ver>1.7.1</resilience4j-spring-boot2.ver>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- Circuit Breaker -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<!--<version>${resilience4j-spring-boot2.ver}</version>-->
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<!-- Needed for AbastractDiscoveryClientOptionalArgs -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<version>${jersey-apache-client4.ver}</version>
</dependency>
<!-- UTILITIES -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- TESTING -->
<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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
application.yml
server:
port: 8765
spring:
application:
name: api-gateway
#config first. Configuration Server not registered in cloud
cloud:
config:
discovery:
enabled: true
service-id: config-server
profile: default
label: latest
fail-fast: true
circuitbreaker:
resilience4j:
enabled: true
main:
banner-mode: off
eureka:
instance:
securePortEnabled: false
nonSecurePortEnabled: true
trust-all-certs: true
trust-all-hostnames: true
client:
enabled: true
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://${hostname}:8761/eureka
#https://github.com/Romeh/spring-cloud-gateway-resilience4j
resilience4j.circuitbreaker:
configs:
default:
slidingWindowSize: 10
minimumNumberOfCalls: 5
permittedNumberOfCallsInHalfOpenState: 3
automaticTransitionFromOpenToHalfOpenEnabled: true
waitDurationInOpenState: 2s
failureRateThreshold: 5
eventConsumerBufferSize: 10
slowCallDurationThreshold: 200ms
slowCallRateThreshold: 30
recordExceptions:
- org.springframework.web.client.HttpServerErrorException
- java.io.IOException
ignoreExceptions:
- java.lang.IllegalStateException
shared:
slidingWindowSize: 100
permittedNumberOfCallsInHalfOpenState: 30
waitDurationInOpenState: 1s
failureRateThreshold: 50
eventConsumerBufferSize: 10
ignoreExceptions:
- java.lang.IllegalStateException
instances:
auth-service:
slidingWindowSize: 1
minimumNumberOfCalls: 10
permittedNumberOfCallsInHalfOpenState: 3
waitDurationInOpenState: 1s
failureRateThreshold: 3
eventConsumerBufferSize: 1
resilience4j.timelimiter:
time-limiter-aspect-order: 398
configs:
default:
timeoutDuration: 1s
cancelRunningFuture: false
instances:
auth-service:
timeoutDuration: 250ms
Router:
#Bean
public RouteLocator gatewayRouter(RouteLocatorBuilder builder) {
log.debug(PATH_PREFIX + CloudPath.AUTH_PATH.getPath() + ALL_SUBPATHS);
Collection<GatewayFilter> filters = new ArrayList<>();
filters.add(inspect);
log.debug("######### gatewayRouter INIT"); //happens before circuit breaker configuration
return builder.routes()
.route(p -> p.path(PATH_PREFIX + CloudPath.CONFIG_PATH.getPath() + ALL_SUBPATHS)
.filters(f -> f.filters(filters)) //pre-filter
.uri(buildUri(CloudPath.CONFIG_PATH))
)
.route(p -> p.path(PATH_PREFIX + CloudPath.AUTH_PATH.getPath() + ALL_SUBPATHS)
.filters(f -> f.circuitBreaker(c
-> c.setName(CloudPath.AUTH_PATH.getPath())
.setFallbackUri(AUTH_SERVICE_FALLBACK_URI)
)
)
.uri(buildUri(CloudPath.AUTH_PATH))
)
.build();
}
Custom Authentication route circuit breaker factory:
#Bean(name = "authCktBrkrFactory")
public ReactiveResilience4JCircuitBreakerFactory authServiceCircuitBreakerFactory(CircuitBreakerRegistry circuitBreakerRegistry, TimeLimiterRegistry timeLimiterRegistry) {
log.debug("CIRCUIT BREAKER COUNT = " + circuitBreakerRegistry.getAllCircuitBreakers().asJava().size());
circuitBreakerRegistry.getAllCircuitBreakers().asJava().forEach(b -> log.debug("BREAKER:: " + b.getName()));
ReactiveResilience4JCircuitBreakerFactory reactiveResilience4JCircuitBreakerFactory = new ReactiveResilience4JCircuitBreakerFactory(circuitBreakerRegistry, timeLimiterRegistry);
// inject the created spring managed bean circuit breaker registry will all externally configured CBs
reactiveResilience4JCircuitBreakerFactory.configureCircuitBreakerRegistry(circuitBreakerRegistry);
// Inject the the created spring managed bean time limter config for specific backend name otherwise use the default configuration from resilience4j
reactiveResilience4JCircuitBreakerFactory.configure(
builder -> builder
.timeLimiterConfig(timeLimiterRegistry.getConfiguration(CloudPath.AUTH_PATH.getPath()).orElse(TimeLimiterConfig.custom().timeoutDuration(Duration.ofMillis(300)).build()))
.circuitBreakerConfig(circuitBreakerRegistry.getConfiguration(CloudPath.AUTH_PATH.getPath()).orElse(circuitBreakerRegistry.getDefaultConfig())), CloudPath.AUTH_PATH.getPath()
);
logConfig(reactiveResilience4JCircuitBreakerFactory.getCircuitBreakerRegistry().circuitBreaker(CloudPath.AUTH_PATH.getPath()));
return reactiveResilience4JCircuitBreakerFactory;
}
private void logConfig(CircuitBreaker cb) {
CircuitBreakerConfig cbc = cb.getCircuitBreakerConfig();
StringBuilder msg = new StringBuilder();
msg.append("\n").append(cb.getName());
msg.append("\n\t State = ").append(cb.getState().name());
msg.append("\n\t ").append(cbc.toString().replace("{", "\n\t{\n\t ").replaceAll(",", "\n\t,").replace("}", "\n\t}\n"));
log.debug(msg.toString());
}
LOGS:
2021-11-08 13:46:02,119 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'gatewayRouter'
2021-11-08 13:46:02,120 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'routeLocatorBuilder'
2021-11-08 13:46:02,121 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'org.springframework.cloud.gateway.config.GatewayAutoConfiguration'
2021-11-08 13:46:02,122 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'routeLocatorBuilder' via factory method to bean named 'org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext#61f7b9e8'
2021-11-08 13:46:02,123 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'gatewayRouter' via factory method to bean named 'routeLocatorBuilder'
2021-11-08 13:46:02,126 DEBUG [restartedMain] com.my.gateway.config.ApiGatewayRoutes.gatewayRouter::
/auth-service/**
2021-11-08 13:46:02,126 DEBUG [restartedMain] com.my.gateway.config.ApiGatewayRoutes.gatewayRouter::
######### gatewayRouter INIT
2021-11-08 13:46:02,132 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'pathRoutePredicateFactory'
2021-11-08 13:46:02,151 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'springCloudCircuitBreakerResilience4JFilterFactory'
021-11-08 13:46:02,151 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'org.springframework.cloud.gateway.config.GatewayResilience4JCircuitBreakerAutoConfiguration'
2021-11-08 13:46:02,152 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'authCktBrkrFactory'
2021-11-08 13:46:02,153 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'circuitBreakerRegistry'
2021-11-08 13:46:02,154 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean'
2021-11-08 13:46:02,155 DEBUG [restartedMain] org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass::
Cannot find '.class' file for class [class io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean$$EnhancerBySpringCGLIB$$f70f2830] - unable to determine constructor/method parameter names
2021-11-08 13:46:02,156 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'resilience4j.circuitbreaker-io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties'
2021-11-08 13:46:02,236 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean' via constructor to bean named 'resilience4j.circuitbreaker-io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties'
2021-11-08 13:46:02,239 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'eventConsumerRegistry'
2021-11-08 13:46:02,253 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'circuitBreakerRegistryEventConsumer'
2021-11-08 13:46:02,254 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'taggedCircuitBreakerMetricsPublisher'
2021-11-08 13:46:02,254 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerMetricsAutoConfiguration'
2021-11-08 13:46:02,255 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'taggedCircuitBreakerMetricsPublisher' via factory method to bean named 'simpleMeterRegistry'
2021-11-08 13:46:02,267 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'compositeCircuitBreakerCustomizer'
2021-11-08 13:46:02,269 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'circuitBreakerRegistry' via factory method to bean named 'eventConsumerRegistry'
2021-11-08 13:46:02,269 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'circuitBreakerRegistry' via factory method to bean named 'circuitBreakerRegistryEventConsumer'
2021-11-08 13:46:02,269 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'circuitBreakerRegistry' via factory method to bean named 'compositeCircuitBreakerCustomizer'
2021-11-08 13:46:02,293 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'timeLimiterRegistry'
2021-11-08 13:46:02,293 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'io.github.resilience4j.timelimiter.autoconfigure.TimeLimiterConfigurationOnMissingBean'
2021-11-08 13:46:02,295 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'resilience4j.timelimiter-io.github.resilience4j.timelimiter.autoconfigure.TimeLimiterProperties'
2021-11-08 13:46:02,302 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'timeLimiterEventsConsumerRegistry'
2021-11-08 13:46:02,306 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'timeLimiterRegistryEventConsumer'
2021-11-08 13:46:02,307 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'taggedTimeLimiterMetricsPublisher'
2021-11-08 13:46:02,307 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'io.github.resilience4j.timelimiter.autoconfigure.TimeLimiterMetricsAutoConfiguration'
2021-11-08 13:46:02,308 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'taggedTimeLimiterMetricsPublisher' via factory method to bean named 'simpleMeterRegistry'
2021-11-08 13:46:02,314 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'compositeTimeLimiterCustomizer'
2021-11-08 13:46:02,316 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'timeLimiterRegistry' via factory method to bean named 'resilience4j.timelimiter-io.github.resilience4j.timelimiter.autoconfigure.TimeLimiterProperties'
2021-11-08 13:46:02,317 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'timeLimiterRegistry' via factory method to bean named 'timeLimiterEventsConsumerRegistry'
2021-11-08 13:46:02,317 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'timeLimiterRegistry' via factory method to bean named 'timeLimiterRegistryEventConsumer'
2021-11-08 13:46:02,317 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'timeLimiterRegistry' via factory method to bean named 'compositeTimeLimiterCustomizer'
2021-11-08 13:46:02,333 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'authCktBrkrFactory' via factory method to bean named 'circuitBreakerRegistry'
2021-11-08 13:46:02,333 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'authCktBrkrFactory' via factory method to bean named 'timeLimiterRegistry'
2021-11-08 13:46:02,345 DEBUG [restartedMain] com.my.gateway.config.GatewayCircuitBreakerConfig.authServiceCircuitBreakerFactory:: CIRCUIT BREAKER COUNT = 0
2021-11-08 13:46:02,361 DEBUG [restartedMain] com.my.gateway.config.GatewayCircuitBreakerConfig.logConfig::
auth-service
State = CLOSED
CircuitBreakerConfig
{
recordExceptionPredicate=java.util.function.Predicate$$Lambda$365/341398452#33f6662b
, ignoreExceptionPredicate=io.github.resilience4j.core.predicate.PredicateCreator$$Lambda$655/1600196965#40cacc4c
, recordExceptions=[class org.springframework.web.client.HttpServerErrorException
, class java.io.IOException]
, ignoreExceptions=[class java.lang.IllegalStateException]
, failureRateThreshold=5.0
, permittedNumberOfCallsInHalfOpenState=3
, slidingWindowSize=10
, slidingWindowType=COUNT_BASED
, minimumNumberOfCalls=5
, writableStackTraceEnabled=true
, automaticTransitionFromOpenToHalfOpenEnabled=true
, waitIntervalFunctionInOpenState=io.github.resilience4j.core.IntervalFunction$$Lambda$649/584419470#33b6cd16
, slowCallRateThreshold=30.0
, slowCallDurationThreshold=PT0.2S
}
OF NOTE:
2021-11-08 13:46:02,154 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean'
2021-11-08 13:46:02,155 DEBUG [restartedMain] org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass::
Cannot find '.class' file for class [class io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean$$EnhancerBySpringCGLIB$$f70f2830] - unable to determine constructor/method parameter names
2021-11-08 13:46:02,156 DEBUG [restartedMain] org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton::
Creating shared instance of singleton bean 'resilience4j.circuitbreaker-io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties'
2021-11-08 13:46:02,236 DEBUG [restartedMain] org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray::
Autowiring by type from bean name 'io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerConfigurationOnMissingBean' via constructor to bean named 'resilience4j.circuitbreaker-io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties'

Related

Having "APPLICATION FAILED TO START" error on Spring Boot startup

I'm developing an API on Spring Boot using Vault and Mongo, but it refuses to start.
2022-09-07 13:58:56.510 WARN 23885 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.vault.config.VaultReactiveBootstrapConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.cloud.vault-org.springframework.cloud.vault.config.VaultProperties': Could not bind properties to 'VaultProperties' : prefix=spring.cloud.vault, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2022-09-07 13:58:56.513 INFO 23885 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-07 13:58:56.521 ERROR 23885 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
EDIT: I think the problem is that Spring Boot tries to use javax and jakarta at the same time according to this part of the error:
nested exception is javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found.. Is this a normal behavior?
Consider to bypass the problem: try to add compile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo' to your build.gradle, and #Bean public MongoClient embeddedMongoClient() to return a dummy Mongo client during the Init phase.
The real mongo Url could be fetched (and used) from the Vault later, during run time, once required, via a customized extends of spring-data-mongodb's MongoDbFactory.
Adding hibernate-validator 6 and spring-boot-starter-validation solved the problem.
Thing to know: hibernate-validator < 7 uses Javax, hibernate-validator => 7 uses Jakarta.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.4.Final</version>
</dependency>

Unable to connect app to postgres server using yaml files

Following Error while connecting springboot app service to Postgres using yml.
NOTE: url: jdbc:postgresql://localhost/postgres
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#3f0846c6' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f0846c6': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1429)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636)
... 62 common frames omitted
Caused by: java.net.UnknownHostException: db
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.postgresql.core.PGStream.<init>(PGStream.java:75)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
... 138 common frames omitted
Please suggest the alternatives and ideas
Well, you did not show your yaml file, that is most important. Error says problem with connection, so make sure your postgres is up and running, you can test it in console like
psql -h localhost -p port(default 5432) -U username -d database
spring:
datasource:
url: jdbc:postgresql://localhost:5432/databaseName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false
username: yourUsername
password: yourPassword
jpa:
hibernate:
ddl-auto: update
show-sql: true
This is example of application.yaml for connecting to postgresql running on your machine, i am using docker for databases,so it works for that as well. Then make sure you have postgresql in your build file. If you use maven, it looks like this
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
And don`t forget JPA, which you probably have, as i see from error, but anyway
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Version is defined as parent. Spring boot makes configuration and connection for you, just by adding dependencies and reading your application.yml file.

error in deploying a SpringBoot webapp into tomcat with MongoDB

I am new to SpringBoot . I have successfully executed a webapp using springboot with embedded tomcat.Facing issue when trying to deploy this spring boot webapp into a external Tomcat server.
I got bellow error
Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456) [catalina.jar:7.0.54]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.54]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_60]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 26 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 28 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 40 common frames omitted
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:180) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:121) ~[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 41 common frames omitted
2016-03-23 11:55:09.834 INFO 8268 --- [ost-startStop-1] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/classes/, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/aopalliance-1.0.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/classmate-1.1.0.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/hibernate-validator-5.2.4.Final.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-annotations-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-core-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jackson-databind-2.6.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jboss-logging-3.3.0.Final.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jcl-over-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/jul-to-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/log4j-over-slf4j-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/logback-classic-1.1.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/logback-core-1.1.5.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/mongo-java-driver-2.13.3.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/mysql-connector-java-5.1.38.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/slf4j-api-1.7.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/snakeyaml-1.16.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-aop-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-beans-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-autoconfigure-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-data-mongodb-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-logging-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-security-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-validation-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-boot-starter-web-1.3.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-context-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-core-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-data-commons-1.11.4.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-data-mongodb-1.8.4.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-expression-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-jdbc-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-orm-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-config-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-core-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-security-web-4.0.3.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-tx-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-web-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/spring-webmvc-4.2.5.RELEASE.jar, file:/C:/SATYAJIT/Recrosoft/workplace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/springDemo/WEB-INF/lib/validation-api-1.1.0.Final.jar]
2016-03-23 11:55:09.839 ERROR 8268 --- [ina-startStop-1] org.apache.catalina.core.ContainerBase : A child container failed during start
I am using spring boot 1.3.3 with jdk7.
any help would be good - as anyone had similar problems when deploying spring boot apps as a WAR into a external server?
Here are my files
pom.xml
<project.......>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<groupId>SpringBootDemo</groupId>
<artifactId>SpringBootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootDemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<finalName>SpringBootDemo</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
ApplicatationStart.java
package com.springDemo;
#Configuration
#ComponentScan(basePackages="com.springDemo")
#EnableAutoConfiguration
#SpringBootApplication
public class ApplicatationStart extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApplicatationStart.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(ApplicatationStart.class, args);
}
}
application.properties
server.contextPath =/springDemo
#for mongo db
spring.data.mongodb.uri=mongodb://localhost/admin
#spring.data.mongodb.host=localhost
#spring.data.mongodb.port=27017
# security properties
security.basic.enabled=false
management.security.enabled=false
The point is that the spring-boot-starter-security is pulling the spring-jdbc dependency. This dependency triggers the DataSourceAutoConfiguration to create a DataSource as you haven't defined one explicitly it assumes an in memory on like H2, HSQLDB or Derby. However those aren't on your classpath so startup fails.
Now you have 2 options to fix this. The first is the explicitly disable the DataSourceAutoConfiguration by adding it as an exclude to the #SpringBootApplication annotation.
#SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
public class ApplicatationStart extends SpringBootServletInitializer { ... }
Pro Tip: You should also remove the #Configuration, #ComponentScan and #EnableAutoConfiguration as those are implied by #SpringBootApplication.
The other option is to exclude the spring-jdbc dependency from the spring-boot-starter-security dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<excludes>
<exclude>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclude>
</excludes>
</dependency>

wildfly-8.1.0.Final Failed instantiate InitialContextFactory

im getting following Error
**ERROR:**
2014-10-07 16:33:46,692 ERROR [stderr] (default task-1) javax.naming.NamingException:
JBAS011843: **Failed instantiate** **InitialContextFactory
org.jboss.naming.remote.client.InitialContextFactory** from classloader
ModuleClassLoader for Module "deployment.wildfly8.1.ear.wildfly8.1-war.war:main"
from Service Module Loader [Root exception is java.lang.ClassNotFoundException:
org.jboss.naming.remote.client.InitialContextFactory from [Module
"deployment.wildfly8.1.ear.wildfly8.1-war.war:main" from Service Module Loader]]
Code:
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "127.0.0.1");
//OR env.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(env);
Try adding a jboss-deployment-structure.xml to the META-INF of the top level .ear file. In the jboss-deployment-structure.xml add a dependency for org.jboss.remote-naming and org.jboss.ejb-client.
Here's some documentation on jboss-deployment-strucure.xml: Class Loading in WildFly
Other useful links:
EJB invocations from a remote server instance
ejb-multi-server: EJB Communication Across Servers
You'll need to include in your war/WEB-INF/lib directory all dependencies of a remote client:
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>${version.wildfly}</version>
<type>pom</type>
</dependency>

JBoss 6 DataSource JNDI Not Found

I am trying to deploy .war file on JBoss 6 and I have made MySql datasource which I want to access using JNDI.
My Config looks like this :
in myDB-mysql-ds.xml
jndi-name : MyDataSource
in jboss-web.xml
res-ref-name : jdbc/MyDataSource
res-type : javax.sql.DataSource
jndi-name : java:/MyDataSource
in applicationContext.xml
property name="jndiName"
& its value : java:comp/env/jdbc/MyDataSource
When I deploy this war file, It gets bound to MyDatasource like,
INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MyDataSource' to JNDI name 'java:MyDataSource'
but still I get error :
ERROR [[/AppName]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: JNDI object with [java:comp/env/jdbc/MyDataSource] not found: JNDI implementation returned null
It is because you are accessing it some wrong way. You should do the following,
<use-java-context>false</use-java-context>
and then access it by its JNDI name.