I just created a project in spring boot, the project is clean (zero changes) just created and at first I wanted to build it with the command: ./gradlew clean build , but the build does not go through I get: BUILD FAILED (Task :test FAILED) What went wrong: Execution failed for task ':test'. java.lang.IllegalStateException: Failed to load ApplicationContext I have no idea why I'm getting an error in an application where I haven't modified anything yet. What could be the cause of this? How can I build this application?
SpringbootServerApplicationTests > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:658
Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:185
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException at DataSourceProperties.java:182
gradle.build
plugins {
id 'org.springframework.boot' version '2.7.2'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
ERROR:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
at app//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
at app//org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
I think you have default test and you dont have main method that starts application. Maybe you can write some code to provide spring application to boot. Main method is enough for you. contextLoads() method test the application context be up or not. You need configure datasource as well. In your stacktrace I can see that driver is missing.
Related
I'm migrating a small java 8 Spring-Boot 2.1.0 project to Java 17 with Spring-Boot 2.6.3
The project uses RabbitMQ and is basically a serializer-deserializer.
The problem I'm encountering is that I cannot run the application because it fails to initialize this bean:
#Autowired
private ConnectionFactory connectionFactory;
#Bean
public IntegrationFlow fromDocToLDocFlow(AmqpTemplate amqpTemplate) {
return IntegrationFlows
.from(DOCUMENT_ROUTE)
.handle(Amqp.outboundAdapter(amqpTemplate).routingKey(documentBinding).exchangeName(documentExchange))
.get();
}
And the exception I get is this:
Error creating bean with name 'fromDocToLDocFlow.amqp:outbound-channel-adapter#0' defined in class path resource [publisher/config/IntegrationFlowConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.IncompatibleClassChangeError: Expecting non-static method 'java.lang.Object org.springframework.integration.context.IntegrationObjectSupport.extractTypeIfPossible(java.lang.Object, java.lang.Class)'... 14 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: Expecting non-static method 'java.lang.Object org.springframework.integration.context.IntegrationObjectSupport.extractTypeIfPossible(java.lang.Object, java.lang.Class)'
at org.springframework.integration.amqp.outbound.AbstractAmqpOutboundEndpoint.doInit(AbstractAmqpOutboundEndpoint.java:409) ~[spring-integration-amqp-5.1.0.RELEASE.jar:5.1.0.RELEASE]
... 26 common frames omitted
Here is my gradle configuration:
buildscript {
ext {
springBootVersion = '2.6.3'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.group'
sourceCompatibility = 17
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-amqp')
implementation('org.springframework.boot:spring-boot-starter-integration')
implementation("org.springframework.integration:spring-integration-feed:5.1.0.RELEASE")
implementation("org.springframework.integration:spring-integration-amqp:5.1.0.RELEASE")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")
implementation("org.apache.commons:commons-lang3:3.12.0")
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testImplementation("junit:junit")
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('commons-io:commons-io:2.11.0')
}
Compiled dependencies:
Gradle: org.springframework.amqp:spring-rabbit:2.4.22
Gradle: org.springframework.amqp:spring-amqp:2.4.22
Gradle: org.springframework.boot:spring-boot:2.6.32
Gradle: org.springframework.retry:spring-retry:1.3.1
I'm migrating Optaplanner from v7.x to v8.14 on a project that uses spring-boot (as a web api).
I've added the optaplanner-spring-boot-starter dependency to the project, however when starting the application, I got the following error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solverManager' defined in class path resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at be.my.WebgardesApplication.main(WebgardesApplication.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 24 common frames omitted
Caused by: java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.processSolutionAnnotations(SolutionDescriptor.java:269)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.processAnnotations(SolutionDescriptor.java:212)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.buildSolutionDescriptor(SolutionDescriptor.java:120)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolutionDescriptor(DefaultSolverFactory.java:160)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildScoreDirectorFactory(DefaultSolverFactory.java:133)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolver(DefaultSolverFactory.java:87)
at org.optaplanner.core.impl.solver.DefaultSolverManager.validateSolverFactory(DefaultSolverManager.java:69)
at org.optaplanner.core.impl.solver.DefaultSolverManager.<init>(DefaultSolverManager.java:58)
at org.optaplanner.core.api.solver.SolverManager.create(SolverManager.java:111)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration.solverManager(OptaPlannerAutoConfiguration.java:98)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a.CGLIB$solverManager$2(<generated>)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a$$FastClassBySpringCGLIB$$40c364cf.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a.solverManager(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 25 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
Caused by: java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
The project is in two separated modules, one with everything related to Optaplanner (the config.xml, the .drl, the Solution, etc), the other is the spring-boot web api.
Here are the dependencies (.gradle) for both :
module "my-roster"
dependencies {
implementation 'org.springframework:spring-web:5.1.6.RELEASE'
implementation 'org.springframework:spring-context:5.0.10.RELEASE'
implementation 'org.springframework.boot:spring-boot:2.1.4.RELEASE'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:27.0.1-jre'
implementation "org.mapstruct:mapstruct:1.3.0.Final"
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
implementation "org.optaplanner:optaplanner-core:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-persistence-xstream:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-spring-boot-starter:${optaplannerVersion}"
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.11.0'
implementation "org.zalando:problem-spring-web:0.24.0-RC.0"
implementation "net.logstash.logback:logstash-logback-encoder:5.2"
runtimeOnly 'org.springframework.boot:spring-boot-devtools:2.1.4.RELEASE'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
testAnnotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5.12'
implementation 'org.json:org.json:chargebee-1.0'
implementation 'org.apache.commons:commons-lang3:3.0'
}
module "web-app"
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner'
implementation "org.zalando:problem-spring-web:0.24.0-RC.0"
implementation "net.logstash.logback:logstash-logback-encoder:5.2"
implementation "org.optaplanner:optaplanner-core:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-persistence-xstream:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-spring-boot-starter:${optaplannerVersion}"
implementation project(':my-roster')
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.7'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.7'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5.12'
implementation 'org.json:org.json:chargebee-1.0'
}
the SolverConfig file :
<solver xmlns="https://www.optaplanner.org/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.optaplanner.org/xsd/solver https://www.optaplanner.org/xsd/solver/solver.xsd">
<solutionClass>be.my.domain.MySolution</solutionClass>
<entityClass>be.my.domain.DutyAssignment</entityClass>
...
</solver>
And the MySolution file :
package be.my.domain;
// Imports ...
#PlanningSolution
#XStreamAlias("MySolution")
public class MySolution extends AbstractPersistable {
private static final long serialVersionUID = 1L;
private String code;
//All the #ProblemFactProperty / CollectionProperty and the ProblemEntityCollectionProperty
#PlanningScore
private HardMediumSoftScore score;
public MySolution(){}
//A lot of getters
}
EDIT : The #PlanningSolution class and the configuration files are in one module, the solverConfig, solverFactory, scoreManager, etc. are all built in the other package, could this be an issue in v8+ ?
This is a bug in Optaplanner, the current workaround is to move the needed code from the different modules into one. Not ideal, but it works. To follow the issue : https://issues.redhat.com/browse/PLANNER-2600 Once resolved, this bug should not happen anymore.
I have a problem..
I want to deploy my Spring Boot Gradle app to GC App Engine.
I use the command :
gradle appengineDeploy
It actually works but when i try to open the app in the browser it says :
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
So the app was deployed successfully but it has a problem to start..
java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cloudSqlDataSourceProperties' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/sql/GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart (ServletContainerInitializersStarter.java:68)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext (ServletContextHandler.java:330)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp (WebAppContext.java:1406)
at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp (AppEngineWebAppContext.java:175)
at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1368)
at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:778)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:262)
at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:522)
at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart (AppEngineWebAppContext.java:120)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler (AppVersionHandlerMap.java:240)
at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler (AppVersionHandlerMap.java:178)
at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest (JettyServletEngineAdapter.java:120)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest (JavaRuntime.java:728)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest (JavaRuntime.java:691)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run (JavaRuntime.java:661)
at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run (JavaRuntime.java:853)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run (ThreadGroupPool.java:270)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cloudSqlDataSourceProperties' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/sql/GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate (ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod (ConstructorResolver.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod (AbstractAutowireCapableBeanFactory.java:1305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java:1144)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java:849)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run (SpringApplication.java:316)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run (SpringBootServletInitializer.java:157)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext (SpringBootServletInitializer.java:137)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup (SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup (SpringServletContainerInitializer.java:171)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup (ContainerInitializer.java:140)
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart (ServletContainerInitializersStarter.java:63)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate (ConstructorResolver.java:622)
Caused by: java.lang.IllegalStateException: Unable to set ApplicationName - SQLAdmin client already initialized.
at com.google.cloud.sql.core.CoreSocketFactory.setApplicationName (CoreSocketFactory.java:341)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.cloudSqlDataSourceProperties (GcpCloudSqlAutoConfiguration.java:209)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e.CGLIB$cloudSqlDataSourceProperties$0 (<generated>)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e$$FastClassBySpringCGLIB$$a426c72d.invoke (<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper (MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept (ConfigurationClassEnhancer.java:363)
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$bb6c42e.cloudSqlDataSourceProperties (<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java:154)
So it is caused by
Unable to set ApplicationName - SQLAdmin client already initialized.
my build.gradle looks like this
buildscript { // Configuration for building
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.+' // Latest 1.x.x releas
}
}
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
group = 'de.msm'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = 1.8 // App Engine Flexible uses Java 8
configurations {
providedRuntime
compileOnly {
extendsFrom annotationProcessor
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
appengine { // App Engine tasks configuration
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
/*
Only for Run
configurations.all {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}*/
repositories {
mavenCentral()
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
task getHomeDir { //To get actual homeDir
doLast {
println gradle.gradleHomeDir
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-jetty')
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.1.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.github.javafaker:javafaker:0.17.2'
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.56'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.1.4.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-mail:2.1.5.RELEASE'
compile 'org.springframework:spring-context-support:5.1.7.RELEASE'
testCompile 'io.rest-assured:rest-assured:4.0.0'
compile 'io.rest-assured:xml-path:4.0.0'
compile 'io.rest-assured:json-path:4.0.0'
testCompile 'io.rest-assured:json-schema-validator:4.0.0'
compile group: 'joda-time', name: 'joda-time', version: '2.10.3'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.1'
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
compile group: 'org.xhtmlrenderer', name: 'flying-saucer-pdf', version: '9.1.18'
compile "org.apache.pdfbox:pdfbox-tools:2.0.3"
compile "com.itextpdf:itextpdf:5.5.10"
compile "com.itextpdf.tool:xmlworker:5.5.10"
compile "org.apache.poi:poi-ooxml:3.15"
compile "org.apache.poi:poi-scratchpad:3.15"
compile "xerces:xercesImpl:2.8.0"
compile "org.slf4j:slf4j-nop:1.8.0-beta4"
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'com.google.cloud', name: 'google-cloud-storage', version: '1.91.0'
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-sql-postgresql', version: '1.1.3.RELEASE'
compile 'com.google.appengine:appengine-api-1.0-sdk:+'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
}
```
I dont understand whats the problem..
While running from IDE everything looks fine
Getting a below-mentioned error while trying to deploy the application in the tomcat server.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
Application.java
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
build.gradle
plugins {
id 'java'
}
sourceCompatibility = 1.8
apply plugin: 'java'
apply plugin: 'war'
repositories {
mavenCentral()
maven { url "http://dayrhebfmi001.enterprisenet.org:8081/artifactory/libs-snapshot"}
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.7.RELEASE'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.6'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.28'
testCompile group: 'junit', name: 'junit', version: '4.12'
providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.1.8.RELEASE'
}
application.properties
spring.datasource.platform=xxxxx
spring.datasource.url=xxxxx
spring.datasource.username=xxxxx
spring.datasource.password=xxxxx
spring.jpa.show-sql=true
spring.datasource.driver-class-name=org.postgresql.Driver
Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
There are a couple things that look suspicious about your properties. But I think you can solve this specific error by giving it the class name as requested.
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
(or whatever DB you're using)
Extra points for adding
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
(again, or whatever DB you're using)
EDIT:
Of course unless you've put the database driver jar file in tomcat/lib, you'll need to add that to your dependencies such that it can get bundled into the war file.
You should add driver class configuration to application.properties:
spring.datasource.driver-class-name=org.postgresql.Driver
An error occurred after executing the spring. Please tell me how to fix it.
I need your help.
Error
2019-01-22 20:23:25.416 INFO 8692 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 19145 ms
2019-01-22 20:23:25.759 ERROR 8692 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.session.RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.NoSuchMethodError: org.springframework.boot.autoconfigure.session.RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.setCleanupCron(Ljava/lang/String;)V
2019-01-22 20:23:25.839 WARN 8692 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
:bootRun FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_121\bin\java.exe'' finished with non-zero exit value 1
build.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contentsbuild.gradle contents
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
dependencies {
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.46'
compile('org.springframework.boot:spring-boot-starter-data-jpa:2.0.0.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web:2.0.0.RELEASE')
compile('javax.validation:validation-api:2.0.0.Final')
compile('org.apache.commons:commons-lang3:3.6')
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.14.Final'
compile files('lib/gsf-3.0.jar')
// new
compile ('com.voodoodyne.jackson.jsog:jackson-jsog:1.0')
compile('org.springframework.boot:spring-boot-starter-security:2.0.0.RELEASE')
compile('org.springframework.boot:spring-boot-starter-thymeleaf:2.0.0.RELEASE')
compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0')
compile ('com.google.guava:guava:23.3-jre')
compile('org.springframework.session:spring-session:1.3.1.RELEASE')
compile('org.springframework.session:spring-session-data-redis:1.3.1.RELEASE')
compile('org.glassfish:javax.el:3.0.1-b08')
compile("com.querydsl:querydsl-core:4.1.4")
compile("com.querydsl:querydsl-jpa:4.1.4")
compile("com.querydsl:querydsl-apt:4.1.4")
compile('org.springframework.data:spring-data-redis:2.0.5.RELEASE')
compile('org.springframework.data:spring-data-jpa:2.0.5.RELEASE')
compile('org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE')
compile('org.springframework.security:spring-security-core:5.0.3.RELEASE')
compile('com.squareup.okhttp3:okhttp:3.8.0')
compile('com.squareup.retrofit2:retrofit:2.3.0')
compile('com.github.iamport:iamport-rest-client-java:0.1.10')
compile('com.alibaba:fastjson:1.2.47')
compile ('org.json:json:20180813')
compile ('org.apache.xmlgraphics:batik-transcoder:1.7')
compile('org.springframework:spring-test:2.5')
compile('commons-validator:commons-validator:1.6')
runtime('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok:1.16.20')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Adding below dependency helped me to solve the above issue.
compile "org.springframework.session:spring-session-data-redis:2.0.3.RELEASE"