How to integrate mysql or mongodb to grails 3.2.10 - mysql

I'm about start with a web application project and I am trying to integrate Mysql into Grails 3. All of the online tutorials show us to change the DataSource file which does not currently (there is Application.yml).
I tried changing the Application.yml as given in the official documentation, but it gives me a big error. Its a new project and has no other changes to it. I've used grails 2.4 previously, it was really easy with that and now I'm thinking of changing back.
Change:
dataSource :
pooled : true
dbCreate : "update"
url : "jdbc:mysql://localhost:3306/my_database"
driverClassName : "com.mysql.jdbc.Driver"
dialect : org.hibernate.dialect.MySQL5InnoDBDialect
username : "username"
password : "password"
properties :
jmxEnabled : true
initialSize : 5
maxActive : 50
minIdle : 5
maxIdle : 25
maxWait : 10000
maxAge : 10 * 60000
timeBetweenEvictionRunsMillis : 5000
minEvictableIdleTimeMillis : 60000
validationQuery : "SELECT 1"
validationQueryTimeout : 3
validationInterval : 15000
testOnBorrow : true
testWhileIdle : true
testOnReturn : false
jdbcInterceptors : "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation :
java.sql.Connection.TRANSACTION_READ_COMMITTED
the error I get:
/usr/lib/jvm/java-8-oracle/bin/java -XX:+TieredCompilation -
XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Dfile.encoding=UTF-8 -
classpath /home/nischit/.gradle/caches/modules-2/files-
2.1/org.grails/grails-
shell/3.2.10/c6b000bbb8ac369a9be062f08e8a0a8d3f85705/grails-shell-
3.2.10.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.slf4j/slf4j-
simple/1.7.25/8dacf9514f0c707cbbcdd6fd699e8940d42fb54e/slf4j-simple-
1.7.25.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.codehaus.plexus/plexus-component-api/1.0-alpha-
33/7d9560effcadf867937ac6885d0d1045ea98ab59/plexus-component-api-1.0-
alpha-33.jar:/home/nischit/.gradle/caches/modules-2/files
Running application...
2017-10-02 01:42:14.120 ERROR --- [ost-startStop-1]
o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat
context. Exception:
org.springframework.beans.factory.BeanCreationException. Message:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.
simple.MemoryPageFragmentCachingFilter]
while setting bean property 'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.
defaultCall(CallSiteArray.java:48)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.simple.
MemoryPageFragmentCachingFilter] while setting bean property
'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error c
reating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.support.
BeanDefinitionValueResolver.resolveInnerBean
(BeanDefinitionValueResolver.java:313)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.annotation.
AutowiredAnnotationBeanPostProcessor
$AutowiredMethodElement.inject
(AutowiredAnnotationBeanPostProcessor.java:667)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with
non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info
or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full
trace)

The problem is with the way you're trying to set the maxAge value on your data source:
Failed to convert property value of type 'java.lang.String' to
required type 'long' for property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
Try just setting a concrete value rather than a calculation.

If you are not very comfortable with YML standard then simply create a new file with name application.groovy, place it inside the conf directory and add the datasource block in that groovy file. Don't forget to remove the data source block from application.yml file.

Related

Broadleaf JUnit Testing Error during loading of ApplicationContext

Using Broadleaf 5.2.2-GA edition Multi-Tenant Version
Have added the below source code for JUnit execution:
package com.test.simple;
import javax.annotation.Resource;
import org.broadleafcommerce.core.catalog.service.CatalogService;
import org.broadleafcommerce.test.config.BroadleafSiteIntegrationTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#BroadleafSiteIntegrationTest
public class JUnitTest {
#Resource
private CatalogService catalogService;
#Test
public void testInjectionWorks() {
Assert.assertNotEquals(catalogService, null);
}
}
Completed the required setup added the below details in site pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>integration</artifactId>
<version>${blc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>integration</artifactId>
<version>${blc.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Got the below error as
Caused by: org.hibernate.exception.GenericJDBCException: Could not
open connection at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
at
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at
org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1395)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:59)
... 71 common frames omitted Caused by:
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver
class 'org.hsqldb.jdbcDriver' at
org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at
org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
at
org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
at
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
... 76 common frames omitted Caused by:
java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
... 81 common frames omitted
Question 1: Why its should ask for HSQL Driver as I have already configured SQL server both admin and site application as coming up?
I have added the below dependency
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>
The error is resolved but a new error came up as per below.
20:38:56.118 [main] ERROR
org.springframework.test.context.TestContextManager - Caught exception
while allowing TestExecutionListener
[org.springframework.test.context.web.ServletTestExecutionListener#15bfd87]
to prepare test instance [com.bv.test.simple.JUnitTest#52d8ada]
java.lang.IllegalStateException: Failed to load ApplicationContext at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at
org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at
org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
at
org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'org.springframework.security.filterChains': Cannot resolve reference
to bean
'org.springframework.security.web.DefaultSecurityFilterChain#0' while
setting bean property 'sourceList' with key [0]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.DefaultSecurityFilterChain#0':
Cannot create inner bean '(inner bean)#861d892' of type
[org.springframework.security.web.authentication.logout.LogoutFilter]
while setting constructor argument with key [4]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#861d892': Cannot resolve
reference to bean
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0'
while setting constructor argument with key [2]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0':
Cannot create inner bean '(inner bean)#1a2955e7' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1a2955e7': Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at
org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:134)
at
org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:61)
at
org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at
org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 common frames omitted Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.DefaultSecurityFilterChain#0':
Cannot create inner bean '(inner bean)#861d892' of type
[org.springframework.security.web.authentication.logout.LogoutFilter]
while setting constructor argument with key [4]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#861d892': Cannot resolve
reference to bean
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0'
while setting constructor argument with key [2]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0':
Cannot create inner bean '(inner bean)#1a2955e7' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1a2955e7': Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at
org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 45 common frames omitted Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#861d892': Cannot resolve
reference to bean
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0'
while setting constructor argument with key [2]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0':
Cannot create inner bean '(inner bean)#1a2955e7' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1a2955e7': Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at
org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
... 59 common frames omitted Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0':
Cannot create inner bean '(inner bean)#1a2955e7' while setting
constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1a2955e7': Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
at
org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648)
at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 69 common frames omitted Caused by:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1a2955e7': Bean instantiation
via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)
... 81 common frames omitted Caused by:
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.security.core.userdetails.UserDetailsService]:
Factory method 'cachingUserDetailsService' threw exception; nested
exception is org.springframework.context.ApplicationContextException:
More than one UserDetailsService registered. Please use a specific Id
reference in or elements. at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 86 common frames omitted Caused by:
org.springframework.context.ApplicationContextException: More than one
UserDetailsService registered. Please use a specific Id reference in
or elements. at
org.springframework.security.config.http.UserDetailsServiceFactoryBean.getUserDetailsService(UserDetailsServiceFactoryBean.java:125)
at
org.springframework.security.config.http.UserDetailsServiceFactoryBean.cachingUserDetailsService(UserDetailsServiceFactoryBean.java:54)
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:162)
... 87 common frames omitted
Please help to check how to resolve this error.
It looks to me that the cause of your current error is the following excerpt from that stacktrace:
org.springframework.context.ApplicationContextException: More than one UserDetailsService registered. Please use a specific Id reference in or elements.
It appears that you have multiple CachingUserDetailsService or UserDetailsService beans being instantiated. If you look at the source for UserDetailsServiceFactoryBean#getUserDetailsService you will see where it verifies there is only one. I would look into your security configuration and figure out why multiple UserDetailsService beans are being registered.

How to run a Spring MVC project on Bluemix?

I have successfully pushed my Spring MVC application to the cloud using Cloud Foundry. However, I get the following exception when I try to access the URL:
Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught
initialization exception created by servlet
Here is the error get when I access the URL:
App/0[ERROR ] Context initialization failed2016-08-27T16:12:30.073+0530
App/0Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.covenant.app.dao.UserRepository com.covenant.app.services.UserService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.073+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)2016-08-27T16:12:30.075+0530
App/0 at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2390)2016-08-27T16:12:30.075+0530
App/0Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:667)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)2016-08-27T16:12:30.074+0530
App/0[ERROR ] SRVE0271E: Uncaught init() exception created by servlet [dispatcher] in application [myapp]: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.covenant.app.dao.UserRepository com.covenant.app.services.UserService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined2016-08-27T16:12:30.074+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:528)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)2016-08-27T16:12:30.074+0530
App/0 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)2016-08-27T16:12:30.075+0530
App/0 ... 28 more2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:572)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:354)2016-08-27T16:12:30.075+0530
App/0 at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:694)2016-08-27T16:12:30.075+0530
App/0 at [internal classes]
Any help would be much appreciated as I am stuck at this point of time. All of my spring MVC configuration is in the Java config. Is there any problem if I have all of it in my Java config when deploying to Bluemix?
I have followed the article and able to deploy and test Spring MVC using bluemix.
Modified MySQL to dashDB (equivalent of IBM DB2). The URL is
http://www.codejava.net/frameworks/spring/spring-mvc-with-jdbctemplate-example. Also tested locally with DB2 and IBM Liberty Server and it works.
The error was that I was calling my local data source for MySQL with DriverManager to get the data source. However, when I changed it to Basic DataSource for Bluemix, it started working.

broken pipe exception with MySql in Grails app

I have deployed a Grails 2.2.1 application to a remote server. After a few hours, when I access to home page of the application, I see the following exception:
Error 500: Internal Server Error
URI
/DocGemStudioZoccali/
Class
java.net.SocketException
Message
Broken pipe
Trace
Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by GroovyPagesException: Error processing GroovyPageView: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->> 631 | runWorker in /index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by JDBCConnectionException: could not execute query
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by CommunicationsException: The last packet successfully received from the server was 138,684,859 milliseconds ago. The last packet sent successfully to the server was 138,684,859 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1116 | createCommunicationsException in com.mysql.jdbc.SQLError
| 3851 | send . . in com.mysql.jdbc.MysqlIO
| 2471 | sendCommand in ''
| 2651 | sqlQueryDirect in ''
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement
| 2310 | executeQuery in ''
| 96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
| 25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by SocketException: Broken pipe
->> 109 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 153 | write in ''
| 82 | flushBuffer in java.io.BufferedOutputStream
| 140 | flush in ''
| 3832 | send . . in com.mysql.jdbc.MysqlIO
| 2471 | sendCommand in ''
| 2651 | sqlQueryDirect in ''
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement
| 2310 | executeQuery in ''
| 96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
| 25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
I've tried to solve the problem as seen in another question in SO, but it does not work for me.
Here is what I've done inside config file:
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = "root"
//run the evictor every 30 minutes and evict any connections older than 30 minutes.
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
//test the connection while its idle, before borrow and return it
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
Notice that, if I refresh the page, everything works correctly. Anybody knows something to solve this issue?
EDIT 1:
I've edited the my.cnf file in /etc folder, adding the following:
wait_timeout = 28800
interactive_timeout = 28800
but nothing changes
EDIT 2:
This is the actual data source that I'm using. Broken pipe still appears
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
EDIT 3:
Here is the stacktrace after the suggestion given by James Kleeh
2015-12-04 17:41:36,924 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
2015-12-04 17:41:36,931 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing Grails: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/DocGemStudioTest] startup failed due to previous errors
2015-12-04 17:41:36,955 [http-bio-8080-exec-63] WARN lifecycle.ShutdownOperations - Error occurred running shutdown operation: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Dec 04, 2015 5:41:36 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/DocGemStudioTest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
EDIT 4:
I've edited the properties block and now application starts. I need to check if error occurs after few hours.
properties{
minIdle = 5
maxIdle = 25
maxWait = 10000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
So I believe everything other than dbCreate, url, username, and password needs to be in a properties block:
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
properties {
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
Although, this should be strange but if the Grails app and the MySQL server both are on the same machine then use localhost or 127.0.0. instead of real IP address xxx.xxx.xxx.xxx
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/docgem_test_db?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
// Your other properties
}
Please try the below not the addition of driverClassName and dialect and I also added pooled in case you need that
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname? useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
properties {
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
Looks to me like MySQL is timing out it's connection to you. Probably not much you can do about that.
Can you consider closing the connection if there's no traffic on it for a while and then re-open it when it's needed again?

How to use datasource conditionally in applicationContext.xml

I'm creating a GAE project with Spring which will also use cloud SQL. While testing this app in local I'm pointing to my local MySQL environment but when I'll deploy it to GAE, it will point to cloud SQL instance. So I want to configure my driverName in datasource bean depending on environment. To this we generally use following in our java code
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
// Load the class that provides the new "jdbc:google:mysql://" prefix.
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://<your-project-id>:<your-instance-name>/<your-database-name>?user=root";
} else {
// Local MySQL instance to use during development.
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://127.0.0.1:3306/<your-database-name>?user=root";
}
Now I want to achieve the same in applicationcontext.xml using Spring Expression language. I haven't done this before and not able to achieve it. Please guide me. This is what I tried
<bean id="isDev" class="java.lang.Boolean">
<constructor-arg value="#{ systemProperties[environment.value] == SystemProperty.Environment.Value.Development ? true : false }" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="#{ isDev ? com.mysql.jdbc.Driver : com.mysql.jdbc.GoogleDriver }" />
.
.
.
But I'm getting exception, attaching a part of exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sandeepapplabs.custengage.services.FeedbackFormService com.sandeepapplabs.custengage.controllers.FeedbackFormController.feedbackFormService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sandeepapplabs.custengage.daos.FeedbackFormDAO com.sandeepapplabs.custengage.services.impl.FeedbackFormServiceImpl.feedbackFormDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormDAO' defined in ServletContext resource [/WEB-INF/custengage-servlet.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/custengage-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.NullPointerException
I believe you need to quote the class names to make them literals...
... 'com.mysql.jdbc.Driver' ...
However it is easier to use Spring Profiles](http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-definition-profiles-xml) and enable the profile you want.
You can use Spring profiles to change concrete bean classes. Let's say you have 2 profiles: "prod" and "dev". Your bean methods should have #Profile annotation as below:
#Configuration
public class AppConfig {
...
#Bean
#Profile("prod")
public Object prodDataSource() {
return new ...
}
#Bean
#Profile("dev")
public Object getDataSource() throws Exception {
return new ...
}
}
If you are using Maven, you can select profile through pom.xml:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profile>dev</spring.profile>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>prod</name>
</property>
</activation>
<properties>
<spring.profile>prod</spring.profile>
</properties>
</profile>
</profiles>
You can pass profile selection argument by -D like: mvn -Dprod clean compile test install
EDIT:
In application.properties following property selects profile:
spring.profiles.active=${spring.profile}

Grails war deployment on Tomcat asking for hsql driver instead of mysql

I have a grails app that I am trying to deploy onto Tomcat. I used to develop on hsql and wanted to use mysql for production. But when I build the war by running
grails prod war demo.war
and deploy the created war in the tomcat/webapps directory, I get the following error
INFO: Deploying web application archive demo.war
2011-11-29 17:30:03,193 [Thread-2] INFO cfg.Environment - Hibernate 3.3.1.GA
2011-11-29 17:30:03,224 [Thread-2] INFO cfg.Environment - hibernate.properties not found
2011-11-29 17:30:03,240 [Thread-2] INFO cfg.Environment - Bytecode provider name : javassist
2011-11-29 17:30:03,251 [Thread-2] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2011-11-29 17:31:25,451 [Thread-2] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.hsqldb.jdbcDriver' for connect URL 'jdbc:mysql://localhost:3306/demoapp?autoreconnect=true'
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
What's puzzling is that I have removed the hsql dependency completely from the Datasource.groovy file. Here is how my Datasource.groovy looks now.
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driver.name = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/demoapp_dev?autoreconnect=true"
username = "root"
password = ""
}
}
test {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp_test?autoreconnect=true"
username = "root"
password = ""
}
}
production {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp?autoreconnect=true"
username = "root"
password = ""
}
}
}
How do I get around this problem? Any help is appreciated.
Try using driverClassName instead of driver.name to define your DataSource driver.
This happens when you don't have the MySQL driver in your class path don't have the driverClassName, as per schmolly159's answer.
Make sure mysql-connector-java-x.x.xx.jar is in your lib directory or declare it as a dependency in BuildConfig.groovy.