dataSource on Websphere liberty - spring

I'm trying to setup a datasource on websphere-liberty:springBoot2 docker image. I'm shared a war file and a server.xml file that contains a jdni definition
<dataSource id="oracle" jndiName="jdbc/oracle">
<jdbcDriver libraryRef="OracleLib"/>
<properties ....... />
</dataSource>
The war file has the bean definition:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/oracle"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
But the next error stack appears:
Invocation of init method failed; nested exception is org.springframework.jndi.JndiLookupFailureException:
JndiObjectTargetSource failed to obtain new target object;
nested exception is javax.naming.NamingException:
CWWKE0800W: An attempt was made to retrieve an initial context for [jdbc/oracle] but no JNDI feature is configured.
I'm shared both the server.xml and the ojdbc8.jar, to container. Thanks in advance.

You need to enable the JNDI feature by adding <feature>jndi-1.0</feature> to the <featureManager> element of your server.xml And you probably want to use the Oracle specific config element properties.oracle not the generic driver config element properties

Related

javax.naming.NameNotFoundException: java:jboss/jms/exampleApp/SampleQueueIn

We are migrating from JBoss EAP 6.4 to JBoss EAP 7.0. Our earlier JMS configuration is not working with JBoss 7.0 where it is throwing NameNotFoundException for my JMS beans
my jms.xml
<beans profile="jboss">
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/jms/exampleApp/ConnectionFactory" />
<property name="resourceRef" value="true" />
</bean>
<bean id="SampleQueueIn" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/jms/exampleApp/SampleQueueIn" />
<property name="resourceRef" value="true" />
</bean>
</beans>
My messageListener.xml
<beans profile="jboss">
<!-- Abstract MessageListener -->
<bean id="messageListener" abstract="true" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="transactionManager" ref="transactionManager" />
<property name="sessionTransacted" value="true" />
<!-- Receive timeout determines the duration of JMS session. Increase from default 1sec to 5sec, to lower the traffic to Queue managers -->
<property name="receiveTimeout" value="5000" />
</bean>
</beans>
my proxy-domain componentContext.xml which has listener beans
<beans profile="jboss">
<bean id="jmsContainer" parent="messageListener">
<property name="destination" ref="SampleQueueIn" />
<property name="messageListener" ref="sampleInformationListenerImpl" />
</bean>
</beans>
commands.cli part for adding admin objects for wmq
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}:activate
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn:add(class-name=com.ibm.mq.connector.outbound.MQQueueProxy,jndi-name=java:jboss/jms/exampleApp/SampleQueueIn)
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn/config-properties=baseQueueName/:add(value=${filter_jms_queue_config_SampleQueueIn_basequeuename})
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn/config-properties=baseQueueManagerName/:add(value=${filter_jms_queue_config_basequeuemanager})
I can see my admin objects in the JBoss for wmq under sub resources with correct jndi-name also.
I am using IBM wmq v9.1.0.2.
[EDIT]
Once I deploy my WAR file, I am getting the below exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SampleQueueIn' defined in class path resource [jms.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jms/exampleApp/SampleQueueIn-- service jboss.naming.context.java.jboss.jms.exampleApp.SampleQueueIn
This configuration was working(still working) in jboss eap 6.4.
I have scourged jboss developer sites & stackoverflow sites but no avail till now!
I can see that my
I resolved the error with reload of JBoss server after running the CLI commands. I automated the execution of both jboss cli commands & reload commands to make sure that the JNDI objects lookup is successful.

Connecting to multiple ActiveMQ Servers using Spring Integration XML Configuration

I have been trying for couple days to set up multiple ActiveMQ connections in Spring Integration using XML configuration.
I am using spring boot, SI looks for a bean called jmsConnectionFactory in the context and uses it. But what if I have to send/listen to jms messages from/to different ActiveMQ servers?
What I have right now is this:
<bean id="jmsConnectionFactory1"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
</property>
<property name="sessionCacheSize" value="10" />
<property name="cacheConsumers" value="false" />
</bean>
<bean id="jmsConnectionFactory2"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.1.59:61616" />
</bean>
</property>
<property name="sessionCacheSize" value="10" />
<property name="cacheConsumers" value="false" />
</bean>
...
<jms:message-driven-channel-adapter channel="jmsInChannel" destination-name="queue.demo" />
<int:channel id="jmsInChannel" />
...
When trying to start the spring boot app I get this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'jmsConnectionFactory' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'jmsConnectionFactory' in 'ActiveMQXAConnectionFactoryConfiguration' not loaded because #ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'
Action:
Consider revisiting the entries above or defining a bean named 'jmsConnectionFactory' in your configuration.
I came across this solution, https://stackoverflow.com/a/43401330/3367392 it's a java configuration. Also I looked into this but it's using camel https://stackoverflow.com/a/13288312/3367392
Is there a way to achieve the same for Spring Integration using XML configuration?
Ok so I got it, for a simple case I just had to add the right connectionFactory to the adapters like this
<jms:message-driven-channel-adapter channel="jmsInChannel"
destination-name="queue.demo"
connection-factory="jmsConnectionFactory1" />

IBM WAS Liberty Error + missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

I'm converting a glassfish project over to IBM WAS Liberty, with much difficulty I am presently having an issue accessing my connection pool configured in Liberty (server.xml) utilizing jndi (jdbc/dataphile).
I contuinually get a missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource error.
Here is some more added detail:
<library id="DB2JCC4Lib">
<fileset dir="C:/MyApps/db2/jdbc" id="db-fileset" includes="db2jcc4-9.5.jar"/>
</library>
<dataSource id="dataSource" jndiName="jdbc/dataphile" type="javax.sql.DataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<connectionManager minPoolSize="2" numConnectionsPerThreadLocal="10"/>
<properties.db2.jcc databaseName="DUNDEEPD" id="DataphileProperties" password="username" portNumber="30001" serverName="xxx.xx.xxx.xxx" user="username"/>
</dataSource>
My stack trace is below;
[ERROR ] Context initialization failed
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine modifiers 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:340)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:232)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getModifiers(MissingResolvedTypeWithKnownSignature.java:104)
at org.aspectj.weaver.ResolvedType.isInterface(ResolvedType.java:876)
at org.aspectj.weaver.ResolvedType.getHierarchy(ResolvedType.java:355)
at org.aspectj.weaver.patterns.KindedPointcut.fastMatch(KindedPointcut.java:126)
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.couldMatchJoinPointsInType(PointcutExpressionImpl.java:84)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:238)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:200)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286)
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:1561)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162)
... 58 more
I am not an expert on this but a similar problem was reported here:
https://developer.ibm.com/answers/questions/9498/datasource-issue-on-liberty-in-spring-hibernate-application.html
The solution required adding this to the datasource:
<property name="resourceRef" value="true" />
<property name="expectedType" value="javax.sql.DataSource"/>
Try creating META-INF/aop.xml file as described in the following post: Why aspect j can't weave show Xlint cantFindType and exclude the com.ibm.ws.rsadapter.jdbc.* classes or better yet, include only your application classes.
I do have enough theory as to why, but this is how I fundamentally how to fix my issue:
Originally, in my Spring XML schema configuration, I had the following:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/mydatasource" />
But I had to convert it to the following:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/mydatasource" />
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
So essentially as suggested I had to enforce this configuration change which added the following properties:
<property name="proxyInterface" value="javax.sql.DataSource"
Hopefully that help someone else out there
Thanks

Spring WorkManagerTaskExecutor cannot initialize in websphere

i want use Websphere work manager for executing async jobs in jee context but i have problem with creating spring WorkManager.
bean definition:
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor"> <property name="workManagerName" value="wm/default" /> </bean>
this definition i found in websphere help. But problem is this ends with noClassDefFound. I noticed pckg org.springframework.scheduling.commonj is missing from spring-context since version 2.x.x
Is it replaced with org.springframework.jca.work.WorkManagerTaskExecutor ?
when i use this other spring class, i get error:
Caused by: org.springframework.jndi.TypeMismatchNamingException:
Object of type [class com.ibm.ws.asynchbeans.WorkManagerImpl]
available at JNDI location [wm/default] is not assignable to
[javax.resource.spi.work.WorkManager]
so whats deal here? thx
was - 7.0.0.23
spring - 3.1.2
Class org.springframework.scheduling.commonj.WorkManagerTaskExecutor resides in spring-context-support-3.1.2.RELEASE.jar
Configuration succeeds with javax.resource.spi.work.WorkManager in applicationContext-service.xml in deployment.....
In my case deployment fails for bean injection org.springframework.scheduling.commonj.WorkManagerTaskExecutor as it fails to take WorkManager JNDI Configured in Application Server.... I just replaced javax.resource.spi.work.WorkManager. And so far it is success deployment.
I yet to see application works fine with it.
<bean id="taskExecutor" class="javax.resource.spi.work.WorkManager">
<property name="workManagerName" value="wm/default" />
</bean>
In our scenario we were managed it by ThreadPoolTaskExecutor instead of WorkManagerTaskExecutor
Here is configuration that comes in ApplicationContext.xml
<!--
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName">
<value>${org.quartz.threadPool.jndi}</value>
</property>
</bean> -->
<!-- Local Thread Pool -->
<bean id="rtSenderTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="${org.quartz.threadPool.corePoolSize}" />
<property name="maxPoolSize" value="${org.quartz.threadPool.maxPoolSize}" />
<property name="queueCapacity" value="${org.quartz.threadPool.queueCapacity}" />
<property name="keepAliveSeconds" value="${org.quartz.threadPool.keepAliveSeconds}"></property>
</bean>

Error upon integrating JNDI with Spring

This was my first attempt at Spring with JNDI but getting the below mentioned exception when trying to create the ApplicationContext like:
ApplicationContext context = new ClassPathXmlApplicationContext("master-job.xml");
The Spring configuration file is as follows:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="/jdbc/Eqpstatus"/>
<property name="resourceRef" value="true" />
</bean>
<bean id="masterDao" class="com.dao.MasterDao">
<property name="dataSource" ref="dataSource"/>
</bean>
On Server i have the required resource entry for the JNDI name.
<Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver"
maxActive="10" maxIdle="2" maxWait="10000" name="jdbc/Eqpstatus"
password="xxxx" type="javax.sql.DataSource"
url="jdbc:oracle:thin:#(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx) (PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx) (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xyz)))"
username="xxx"/>
The error i see is:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Would highly appreciate any inputs on this as am new to Spring-JNDI integration.
First, I think you should use the dedicated tag instead of declaring a "JndiObjectFactoryBean" bean :
<!-- JNDI DataSource for J2EE environments -->
<jee:jndi-lookup id="dataSource" jndi-name="java:jdbc/rppsDS-PUB-PROTO" default-ref="localDataSource" />
<!-- local dataSource for JUnit integration tests -->
<bean id="localDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
Then, you need a jndi.properties file (which could be directly in application server dir such as JBoss) with a content similar to :
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
If you are using Tomcat and everything is fine with your Tomcat configuration; this should be enough:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/dataSource" />
Where jdbc/dataSource is the name defined in your Tomcat config.
EDIT:
My bad, forgot about the jndi.properties; there are two possibilities:
either provide a jndi.properties on your classpath or
set the values in a in the <jee:jndi-environment/> element of <jee:jndi-lookup /> (see reference)
The java.naming.factory.initial property needs to be set for sure, to something like org.apache.naming.java.javaURLContextFactory, possibly some other values as well, like:
java.naming.factory.url.pkgs=org.apache.naming
java.naming.factory.url.pkgs.prefixes=org.apache.naming
java.naming.provider.url=org.apache.naming
Also see reference.

Resources