How to run a Spring MVC project on Bluemix? - mysql

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.

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 integrate mysql or mongodb to grails 3.2.10

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.

Issue with PowerMock - Spring

I am trying to test my CXF web-service - which has in-interceptors and it has the task to modify the JSON received from UI and pass it to a 3rd Party Rest Service.
I am mostly using EasyMock, but since I have to mock the Http rest call too, and the code uses the static class org.apache.http.impl.client.HttpClients, So I am going for PowerMock along with EasyMock.
But I am facing an issue of similar kind like this: PowerMock PrepareForTest annotation causing problems with AmazonSQSClient constructor
Following the solution I have added the
#PowerMockIgnore({ "org.apache.cxf.jaxws.*,sun.security.ssl.*,org.apache.cxf.configuration.jsse.*" })
Still the issue is not getting resolved. I want to understand which packages do I need to include to get rid of this. The error stack trace is:
javax.xml.ws.WebServiceException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '*.*': Cannot create inner bean '(inner bean)' of type [org.apache.cxf.configuration.jsse.TLSClientParametersConfig] while setting bean property 'tlsClientParameters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.apache.cxf.configuration.jsse.TLSClientParameters org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(org.apache.cxf.configuration.security.TLSClientParametersType) throws java.security.GeneralSecurityException,java.io.IOException] threw exception; nested exception is java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: sun.security.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:154)
at com.sun.proxy.$Proxy72.invokeService(Unknown Source)
at com.uhg.pdr.consumer.SelectProfessionalsByIdTypeConsumer.invokeService(SelectProfessionalsByIdTypeConsumer.java:72)
at com.uhg.pdr.providerinfo.SelectProfessionalsByIdTypeProvider.getAssociatedProviders(SelectProfessionalsByIdTypeProvider.java:212)
at com.uhg.util.rest.PropelUtil.getProvidersByMpin(PropelUtil.java:212)
at com.uhg.pdr.interceptor.service.MppBaseInterceptorServiceImpl.getProviders(MppBaseInterceptorServiceImpl.java:302)
at com.uhg.pdr.interceptor.MppBaseInterceptor.handleMessage(MppBaseInterceptor.java:79)
at com.uhg.pdr.bundling.transactions.ProviderLanguageTransactionTest.handleMessageTest(ProviderLanguageTransactionTest.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:148)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.java:140)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.java:131)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.java:140)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
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:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '*.*': Cannot create inner bean '(inner bean)' of type [org.apache.cxf.configuration.jsse.TLSClientParametersConfig] while setting bean property 'tlsClientParameters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.apache.cxf.configuration.jsse.TLSClientParameters org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(org.apache.cxf.configuration.security.TLSClientParametersType) throws java.security.GeneralSecurityException,java.io.IOException] threw exception; nested exception is java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: sun.security.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.configureBean(AbstractAutowireCapableBeanFactory.java:314)
at org.springframework.beans.factory.wiring.BeanConfigurerSupport.configureBean(BeanConfigurerSupport.java:146)
at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:151)
at org.apache.cxf.configuration.spring.ConfigurerImpl.configureWithWildCard(ConfigurerImpl.java:176)
at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:131)
at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:115)
at org.apache.cxf.transport.http.HTTPTransportFactory.configure(HTTPTransportFactory.java:187)
at org.apache.cxf.transport.http.HTTPTransportFactory.getConduit(HTTPTransportFactory.java:270)
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:239)
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:246)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:103)
at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63)
at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:851)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:526)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
... 43 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.apache.cxf.configuration.jsse.TLSClientParameters org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(org.apache.cxf.configuration.security.TLSClientParametersType) throws java.security.GeneralSecurityException,java.io.IOException] threw exception; nested exception is java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: sun.security.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
... 65 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static org.apache.cxf.configuration.jsse.TLSClientParameters org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(org.apache.cxf.configuration.security.TLSClientParametersType) throws java.security.GeneralSecurityException,java.io.IOException] threw exception; nested exception is java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: sun.security.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:169)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
... 70 more
Caused by: java.security.NoSuchAlgorithmException: class configured for KeyManagerFactory: sun.security.ssl.KeyManagerFactoryImpl$SunX509 not a KeyManagerFactory
at sun.security.jca.GetInstance.checkSuperClass(GetInstance.java:258)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:237)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at javax.net.ssl.KeyManagerFactory.getInstance(KeyManagerFactory.java:139)
at org.apache.cxf.configuration.jsse.TLSParameterJaxBUtils.getKeyManagers(TLSParameterJaxBUtils.java:274)
at org.apache.cxf.configuration.jsse.TLSClientParametersConfig.createTLSClientParametersFromType(TLSClientParametersConfig.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149)
... 71 more
Here is my Test class :
#RunWith(PowerMockRunner.class)
#PrepareForTest(ProviderAddressUpdateController.class)
#PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
#PowerMockIgnore({ "org.apache.cxf.jaxws.*,sun.security.ssl.*,org.apache.cxf.configuration.jsse.*" })
#ContextConfiguration(locations = { "classpath:application-context-test.xml" })
public class ProviderLanguageTransactionTest {
.....
.....
.....
#Before
public void setUp() {
.....
.....
}
#Test
public void handleMessageTest() throws Exception {
....
....
}
Issue got resolved by adding #PowerMockIgnore({ "javax.net.ssl.*" })
Also the class inside #PrepareForTest annotation should be the class mocked by PowerMock - not the controller. If you are mocking the HttpClients class,then you should write #PrepareForTest(HttpClients.class) before that method inside which you are mocking.

CAS: "allowedAttributes" is invalid in CAS 4.2.1

Since I have problems with the serviceRegisty.conf, I tried the serviceRegistryDao:
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
<property name="registeredServices">
<list>
<bean class="org.jasig.cas.services.RegisteredServiceImpl">
<property name="id" value="0" />
<property name="name" value="HTTPS" />
<property name="description" value="Only Allows HTTPS Urls" />
<property name="serviceId" value="https://**" />
<property name="evaluationOrder" value="10000001" />
<property name="allowedAttributes">
<list>
<value>cn</value>
<value>description</value>
<value>telephoneNumber</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
If I don't use "allowedAttributes" everything works fine, but I don't get the attributes I want (I get non). So guessed that I need to add which attribute the clients should recieve. However, I get the following exception:
2016-09-21 16:17:40,674 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'centralAuthenticationService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTicketRegistry': Inject
ion of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.jasig.cas.logout.LogoutManager org.jasig.cas.ticket.registry.DefaultTicketRegistry.logoutManager; nested exception is org.springframework.beans.fac
tory.BeanCreationException: Error creating bean with name 'logoutManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.jasig.cas.services.ServicesManager org.jasig.cas.logout.LogoutMana
gerImpl.servicesManager; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servicesManager' defined in URL [jar:file:/D:/Tomcat%20Servers/Tomcat%20CAS%20Server/webapps/cas/WEB-INF/lib/cas-server-core-services-4.2.0.jar!/org/jasig/cas
/services/DefaultServicesManagerImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.jasig.cas.services.ServiceRegistryDao]: : Error creating bean with name 'serviceRegistryDao' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: C
annot create inner bean 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' of type [org.jasig.cas.services.RegisteredServiceImpl] while setting bean property 'registeredServices' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'allowedAttributes' of bean class [org.jas
ig.cas.services.RegisteredServiceImpl]: Bean property 'allowedAttributes' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'serviceRegistryDao' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot create inner bean 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' of type [org.jasig.cas.services.RegisteredServiceImpl] while setting bean property 'registeredServices' with key [0]; n
ested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Error setting property values; nested exception is org.springfram
ework.beans.NotWritablePropertyException: Invalid property 'allowedAttributes' of bean class [org.jasig.cas.services.RegisteredServiceImpl]: Bean property 'allowedAttributes' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1795)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
My suspicion is that this way of dealing with services is no longer supported by CAS 4.2.x, but I am not sure.
EDIT:
I also tried this:
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
<property name="registeredServices">
<list>
<bean class="org.jasig.cas.services.RegexRegisteredService"
p:id="5" p:name="https.all" p:description="Allow HTTPS connection"
p:serviceId="^https://.*" p:evaluationOrder="5" >
<property name="attributeReleasePolicy">
<bean class="org.jasig.cas.services.ReturnAllAttributeReleasePolicy" />
</property>
</bean>
</list>
</property>
</bean>
I thought by that I might get all attributes. I can run the tomcat server now and also log in etc. But I still dont get the attributes.
The configuration is invalid because that's not how 4.2 works. Consult the docs to learn the new syntax. You also need to make sure your application is hitting the right endpoint.

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}