Try to search your question here, if you can't find : Ask Any Question Now ?

Spring boot and gcp starter sql mysql causing test issues

HomeCategory: stackoverflowSpring boot and gcp starter sql mysql causing test issues
Avatarwillson asked 5 days ago

I am using spring boot and gcp starter sql mysql.

It is working well in production however it is not working for tests.

In my tests I have to create different spring contexts.
All these spring contexts are sharing a static class.
When the second context tries to start it fails because the static class has already been initilized any ideas how to handle this? Below is the stacktrace.

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: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.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1255)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
    ... 214 more
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)
    ... 228 more
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$$ce43b5cb.CGLIB$cloudSqlDataSourceProperties$0(<generated>)
    at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$ce43b5cb$$FastClassBySpringCGLIB$$e14cd820.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$$ce43b5cb.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)
    ... 229 more
1 Answers
Best Answer
Avatarnaveen answered 5 days ago
Your Answer

5 + 12 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com