spring not able to find JNDI data source - spring

I am developing a spring web application . A JAR file which I use in my application , is looking for DataSource using JNDI. I configured the element in my tomcat's server.xml. The configuration is as below ,
<GlobalNamingResources>
<Resource name="jdbc/abcd"
auth="Container"
type="javax.sql.DataSource"
maxActive="70"
maxWait="10000"
username="xxxx" password="yyyy"
validationQuery="SELECT 1 from dual"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xx.xxx.xx.xx:xxxx:zzzz"
testOnBorrow="false"
testOnReturn="false"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="120000"
minEvictableIdleTimeMillis="3600000"
/>
</GlobalNamingResources>
The Resource name configured above , "jdbc/abcd" is the same which the JAR is looking for,
But its not able to find this configured data source . Does anyone know what could be the reason ?
Am getting the below exception ,
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

You need to define a ResourceLink in the web application context that makes the global resource visible to the web application.
<ResourceLink
name="nameThatIsVisibleToTheWebApplication"
global="theGlobalName"
...

You need to do more than just configure Spring.
I'd recommend reading Tomcat JNDI documentation and this.

Related

How do we declare jms queue in application.properties of spring boot

Below snippet is available in servlet.xml of Tomcat
<Resource name="jms/queue/NotificationQ"
auth="Container"
type="org.apache.activemq.command.ActiveMQQueue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="NotificationQ"/>
and in context.xml
<ResourceLink name="jms/queue/NotificationQ" global="jms/queue/NotificationQ"/>
Now I am in the process of creating a standalone war file using spring boot. How do I declare the jms queue in spring boot, so that the above configuration works with embedded tomcat?

Can Tomcat support multiple JDBC connection pools?

I have a Spring Boot application which connects to different MySQL databases. I am planning to add connection pool support to this application. Does the Tomcat JDBC Connection Pool (default Spring boot pool) support more than one pool for each of my databases?
Not sure how this would be different under Spring Boot, but for standard web apps you can configure this at the webapp level, by adding in web.xml any number of the following:
<resource-ref>
<res-ref-name>jdbc/yourname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and in context.xml the corresponding number of the following:
<Resource name="jdbc/yourname" auth="Container" type="javax.sql.DataSource"
maxActive="30"
maxIdle="30"
maxWait="2000"
removeAbandoned="true"
...

Tibco EMS with Tomcat configuration

I searched for and answer before posting, but didn't find a solution. If I missed it please link me to it.
Here is my problem. I'm trying to use jndi to connect my tibco server.
Right now I have my resource tag setup inside my tomcat server.xml file:
<Resource name="tibcoConnection"
auth="Container"
type="com.tibco.tibjms.naming.TibjmsInitialContextFactory"
factory="com.tibco.tibjms.naming.TibjmsObjectFactory"
severUrl=<tibcourl>
userName=xxxxxxx
password=xxxxxxx />
For the factory I originally had com.tibco.tibjms.TibjmConnectionFactory but tomcat threw an error cast it to ObjectFactory. So I changed it.
I have my ResourceLink tag in context.xml pointing to the tibcoConnectoin name and type com.tibco.tibjms.naming.TibjmsInitialContextFactory.
My Spring bean is <jee:jndi-lookup id="tibco" jndi-name="tibcoConnection"/>
I'm using the connection for:
<bean class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="tibco"/>
</bean>
I my logs I'm getting a javax.naming.NameNotFoundException: Name [tibco] is not bound in the Context. Unable to find [tibco]
I'm lost since there isn't much documentation out there for tomcat and tibco that I could find. If anyone has had any luck with configuring tomcat with tibco and spring, please help.
Is it possible that the issue might be that you define your resource name as "tibcoConnectoin" ("o" before "i"), but you refer to it in your jndi-lookup as "tibcoConnection" ("o" after "i")?

transaction management using spring jdbc in liferay

I need to implement JTA transaction management using spring jdbc in liferay. I have two databases connected in liferay using jndi. In my project I am doing jdbc CRUD operation using jdbc spring dao and for liferay, it is through liferay build-in service api. For any exception, rollback is working fine for other db but it is not working for liferay.
Below is my code sample:
In portal-ext.prop I have defined
transaction.management.impl= <JTATransactionmanager>
In my project's context.xml of tomcat I have defined user transaction as mentioned at liferay's site :
context.xml
`<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" />
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="600" /><br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/LiferayPool" username="root" password="" url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}<br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/test" username="root" password="" url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}
`
In bean.xml of my project :
<tx:annotation-driven transaction-manager="txManager"/>
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/test"/>
</beans:bean>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
in my class:
#Transactional(rollback{myexception.class})
public void test()
first of all put an eye on this discussion.
What you wouldn't forget is that Liferay rollbacks both for PortalException or SystemException... but it rollbacks only the beans injected inside the current transaction context.
This means that you shouldn't use XLocalServiceUtil, but the injected xLocalService bean.
To get it you need to advice your service layer by service.xml declarations or, inside your serviceImpl class, by adding and referring to:
#BeanReference(type=XArticleLocalService.class)
protected XArticleLocalService xArticleLocalService;
I hope this can help you.
I believe you are using the XXXServiceUtil.java. Whenever you use ServiceUtil, any method you call executes under a different transaction manager (regardless of current thread transaction state) as it's a completely different class loader. Remember in Liferay, every portlet/plugin has its own class loader.

hibernate.cfg.xml fails to reload with Tomcat/Spring 2

I'm using an older Spring 2 application with Tomcat and Hibernate. I was under the impression that I could change some settings in hibernate.cfg.xml, restart Tomcat, and the new settings (like a database connection) would take effect. Yet the old settings persist. What do I have to do to make these new changes go through? Here is an example of the xml:
<property name="connection.username">career</property>
<property name="connection.url">jdbc:oracle:thin:#192.168.76.46:1521:ISDD</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="myeclipse.connection.profile">my-careers</property>
<property name="connection.password">farcri</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
Let me know if more information is required.
i am not sure what your new settings are.Anyway they should be found.do you want to change database from one provider to oracle.Please put your tomcat output..You can do one thing that include log4j jar files so that you can see what tomcat is doing in detail manner.i think you are using myeclipse..do project clean such things..go to project and right click then do refresh..do close myeclipse and start again.
Hope this helps to you to figure out your problem.
As it turns out, hibernate.cfg.xml was not being read by the application. Instead, the database connection settings were placed in the ROOT.xml file in localhost. Not sure why this would be advantageous. Here is the relevant section of the ROOT.xml file:
<Resource name="jdbc/careers" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#192.168.76.55:1521:ISDD"
username="career" password="farcri" maxActive="20" maxIdle="10"
maxWait="-1"/>

Resources