Datasource issue on liberty in Spring hibernate Application - spring

I have a spring and hibernate application that we are trying to port from Jboss to WAS Liberty profile. When the spring factory gets initialized I am getting below error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDatasource': Post-processing of the FactoryBean's object failed; nested exception is org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine superclass of missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource [Xlint:cantFindType]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:165)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322) ... 87 more Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine superclass of missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource [Xlint:cantFindType]
at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:129)
at org.aspectj.weaver.Lint$Kind.signal(Lint.java:325)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:232)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getSuperclass(MissingResolvedTypeWithKnownSignature.java:98)
at org.aspectj.weaver.patterns.KindedPointcut.fastMatch(KindedPointcut.java:144)
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.couldMatchJoinPointsInType(PointcutExpressionImpl.java:82)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:236)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:198)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:252)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:284)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1598)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162) ... 92 more
My Server has following datasource config
<dataSource id="MyDS" jdbcDriverRef="Oracle" jndiName="jdbc/myDS">
The datasource bean on application context is defined as below
<bean id="myDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS" />
</bean>
I would appreciate help. It seems something to do with classloading but I am not able to figure out.

try to specify the following properties to your datasource bean definition:
<bean id="myDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>

The proxyInterface solution worked for me on WAS 8.5.5 Liberty Profile.
On WAS 7, this also works as an alternate solution:
<jee:jndi-lookup id="WASdataSource" jndi-name="java:comp/env/jdbc/admt" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.WebSphereDataSourceAdapter">
<property name="targetDataSource" ref="WASdataSource"/>
</bean>

Related

Spring Social applicationURL setup exception

For Spring Social version 1.1.0.RELEASE, I need to set up the applicationUrl for the ProviderSignInController, as my application (a Tomcat app) is hosted behind a proxy (Apache web server). According the Spring Social document, I set it up as below:
<bean id="providerSignInController"
class="org.springframework.social.connect.web.ProviderSignInController">
<property name="signInUrl" value="/accounts/login" />
<property name="signUpUrl" value="/accounts/signup" />
<property name="postSignInUrl" value="/accounts/profile" />
<property name="applicationUrl" value="${applicationUrl}" />
</bean>
However, when deploying the application, I get an exception in Tomcat catalina.out saying:
PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property
'applicationUrl' threw exception; nested exception is
java.lang.NullPointerException>org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0'
defined in ServletContext resource [/WEB-INF/spring-servlet.xml]:
Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'providerSignInController' defined in ServletContext
resource [/WEB-INF/spring-servlet.xml]: Error setting property values;
nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property
'applicationUrl' threw exception; nested exception is
java.lang.NullPointerException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
Any suggestions please? Thanks.
It should be a bug with class ProviderSignInController in Spring Social version 1.1.0.RELEASE. In class ProviderSignInController, connectSupport is created after properties being set:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
};
Therefore when method setApplicationUrl is invoked, connectSupport is still null.
Now when I configure it in the way shown below, it works. Or if I revert to version 1.0.3.RELEASE, it works fine too.
<bean id="providerSignInController"
class="org.springframework.social.connect.web.ProviderSignInController">
<property name="signInUrl" value="/accounts/login" />
<property name="signUpUrl" value="/accounts/signup" />
<property name="postSignInUrl" value="/accounts/profile" />
</bean>
<bean
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="providerSignInController" />
<property name="targetMethod" value="setApplicationUrl" />
<property name="arguments">
<list>
<bean class="java.lang.String">
<constructor-arg value="${applicationUrl}" />
</bean>
</list>
</property>
</bean>
Follow-up
This problem has been resolved in Spring Social version 1.1.3.RELEASE. In class ProviderSignInController, method afterPropertiesSet has been updated to:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
if (this.applicationUrl != null) {
this.connectSupport.setApplicationUrl(applicationUrl);
}
};
As a result, the workaround of configuration given above (by the way, would not work with Spring Social version 1.1.3.RELEASE any more) can now be simplified to:
<bean id="providerSignInController"
class="org.springframework.social.connect.web.ProviderSignInController">
<property name="signInUrl" value="/accounts/login" />
<property name="signUpUrl" value="/accounts/signup" />
<property name="postSignInUrl" value="/accounts/profile" />
<property name="applicationUrl" value="${applicationUrl}" />
</bean>

org.springframework.beans.factory.support.DefaultListableBeanFactory Destroy method on bean with name 'applicationResource' threw llegalStateException

This really drove me crazy, Here is the software stack I'm using for my current project.
Jersey(Rest layer), Spring jdbc mixed with Spring jpa data, everything works well until I shut down tomcat. I see below message on the console:
2013-12-07 19:40:55,760 ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory(ln513) - Destroy method on bean with name 'applicationResource' threw an exception
java.lang.IllegalStateException
at com.sun.jersey.server.impl.ThreadLocalHttpContext.getRequest(ThreadLocalHttpContext.java:82)
at com.sun.jersey.server.impl.application.WebApplicationImpl$2.invoke(WebApplicationImpl.java:286)
at com.sun.proxy.$Proxy53.hashCode(Unknown Source)
at com.my.resource.BaseResource.hashCode(BaseResource.java)
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1175)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:357)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:220)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:510)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:740)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:455)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:558)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
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:744)
2013-12-07 19:40:55,761 INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean(ln441) - Closing JPA EntityManagerFactory for persistence unit 'myEntity'
When I used pure jdbc, I didn't see this error, I know this error started to crawl off after introducing jpa, and The error was thrown when PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:357) was called.
My dao.xml setting
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" p:driverClass="${jdbc.driverClassName}"
p:password="${jdbc.password}" p:jdbcUrl="${jdbc.url}" p:user="${jdbc.username}"
p:initialPoolSize="10" p:minPoolSize="10" p:maxPoolSize="50"/>
<bean id="nameParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"
c:dataSource-ref="dataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaDialect">
<bean class="com.mycompany.hibernate.config.HibernateExtendedJpaDialect"/>
</property>
<property name="persistenceUnitName" value="myEntity"/>
</bean>
<jpa:repositories base-package="com.mycompany.repository"/>
All of my Jersey Resources are annotated with #Component.
Can you guys see what went wrong?
Thanks, I appreciate your time.
Paul

#Resource dataSource mappedName - overriding to test in non JNDI env

I have an existing service bean which we deployed in Jboss. Unfortunatly it's dataSource reference is configured to inject the datasource reference via the "mappedName" lookup of the JNDI Service.
#Resource(name = "dataSource", mappedName = "java:/OracleDS")
private DataSource dataSource = null;
I want to test the bean in a non JNDI env. I expected to get this exception when i run in a non JNDI env.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'myService': Injection of resource fields failed; nested exception
is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean
definition with name 'java:/OracleDS' defined in JNDI environment: JNDI lookup
failed; nested exception is javax.naming.NoInitialContextException: Need to
specify class name in environment or system property, or as an applet parameter,
or in an application resource file: java.naming.factory.initial
I realise the quickest way to fix this is to dropped the mappedName restriction, since then the production or test spring context can define the datasource. But in the case that i can't do this. Is there a way to define an InitialContext via a test spring context to avoid the exception above.
I did some more reading on SimpleNamingContextBuilder and came up with this context setup for my test case. The trick being to use the MethodInvokingFactoryBean to ensure the bind() method is called.
<bean id="jndiContext" class="org.springframework.mock.jndi.SimpleNamingContextBuilder" factory-method="emptyActivatedContextBuilder"/>
<bean id="invokingFactoryBean"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<ref local="jndiContext" />
</property>
<property name="targetMethod">
<value>bind</value>
</property>
<property name="arguments">
<list>
<value>java:/OracleDS</value>
<ref bean="dataSource" />
</list>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${datasource.driverClassName}" />
<property name="url" value="${datasource.url}" />
<property name="username" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
</bean>

Spring, Atomikos, Tibco EMS 5.1 integration issue

I am trying to configure Atomikos in my Spring application. I am using:
Atomikos 3.7.1 (TransactionsEssentials)
Spring 3.0.2
Tibco EMS 5.1
Can some one give me the configuration details for the connection factory using JNDI for JMS and also details regarding Tibco EMS configuration?
I had tried the following:
<bean id="jmsTemplate2" class="org.springframework.jms.core.JmsTemplate" >
<property name="connectionFactory" ref="amqConnectionFactory" />
<property name="defaultDestination" ref="queue" />
<property name="sessionTransacted" value="true"/>
<property name="messageConverter" ref="messageConverter"></property>
</bean>
<bean id="amqConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean" init-method="init">
<property name="uniqueResourceName" value="XAEMS" />
<property name="xaConnectionFactory" ref="connectionFactory" />
<property name="poolSize" value="10" />
</bean>
<jee:jndi-lookup id="connectionFactory" jndi-name="emsConnectionFactory">
<jee:environment>
java.naming.factory.initial=com.tibco.tibjms.naming.TibjmsInitialContextFactory
java.naming.provider.url=tibjmsnaming://localhost:7222
</jee:environment>
</jee:jndi-lookup>
<jee:jndi-lookup id="queue" jndi-name="emsQueue">
<jee:environment>
java.naming.factory.initial=com.tibco.tibjms.naming.TibjmsInitialContextFactory
java.naming.provider.url=tibjmsnaming://localhost:7222
</jee:environment>
</jee:jndi-lookup>
But get this error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amqConnectionFactory' defined in file [C:\springsource\vfabric-tc-server-developer-2.6.4.RELEASE\spring-insight-instance\wtpwebapps\iRebal-Backend-Poc-Web-Integration-Final-xa\WEB-INF\classes\META-INF\spring\batch\jobs\priority-queue.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory' to required type 'javax.jms.XAConnectionFactory' for property 'xaConnectionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory] to required type [javax.jms.XAConnectionFactory] for property 'xaConnectionFactory': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 39 more
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory' to required type 'javax.jms.XAConnectionFactory' for property 'xaConnectionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory] to required type [javax.jms.XAConnectionFactory] for property 'xaConnectionFactory': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl
This answer is too late for the OP, but for the sake of posterity:
The class you want is com.tibco.tibjms.TibjmsXAConnectionFactory.
It seems that in class com.atomikos.jms.AtomikosConnectionFactoryBean you have a field named xaConnectionFactory that its type (or its getter return type) is javax.jms.XAConnectionFactory. However, in Spring configuration file, you configured that field to be set with an instance of which type is com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory.
Apparently com.tibco.tibjms.naming.TibjmsFederatedQueueConnectionFactory is not convertible to javax.jms.XAConnectionFactory.

JMS implementation using JNDI in spring application

I am trying to implement JMS in my spring application. I have defined the JNDI name + queue name in applicationContext.xml as follows:
<bean id="emailQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="java:comp/env/jms/<<Name of JNDI of connection factory>>" />
</bean>
<bean id="emailQueueDestination" class="org.springframework`enter code here`.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="java:comp/env/jms/<<JNDI name of queue>>" />
</bean>
<bean id="emailQueueTemplate" class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
<property name="connectionFactory" ref="emailQueueConnectionFactory" />
<property name="defaultDestination" ref="emailQueueDestination" />
</bean>
<bean id="emailSender" class="<<Package>>.EmailSender" lazy-init="true">
<property name="jmsTemplate">
<ref bean="emailQueueTemplate" />
</property>
</bean>
Now my controller makes a call to the emailSender bean using the following code:
ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
EmailSender sender =(EmailSender)context.getBean("emailSender");
The exception I get is: Error 404: Request processing failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
I am loading the applicationContext.xml at serevr start-up still my code is not able to locate this file.
Can anyone please help.??
make sure your applicationContext.xml file is in your class path then add the class path prefix, You can try some thing like this
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");

Resources