Hello,
I am using Spring 1.2 with Hibernate 3.0.5. My production environment is WebLogic 8.1 SP 5, but for development I'd like to use Tomcat 5.5.9 because it's so much faster to load than WebLogic.
I'm having trouble with the JNDI lookup when deploying the application to Tomcat. I've scoured the web and it looks like I'm not the only one to have this problem, but I haven't been able to find a fix that works. I'll include a lot of info here in the hopes that somebody can give me a hand. The deployment works in WebLogic, so I know I'm close.
============================================
Here's how I've defined the transaction beans in applicationContext.xml:
============================================
<bean id="springJtaTransactionManager"
class="org.springframework.jdbc.datasource.DataSou rceTransactionManager" />
<!-- transaction manager -->
<bean id="jtaTransactionInterceptor"
class="org.springframework.transaction.interceptor .TransactionInterceptor">
<property name="transactionManager">
<ref local="springJtaTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="search*">PROPAGATION_REQUIRED,readOnly,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_3000</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_3000</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_3000</prop>
<prop key="report*">PROPAGATION_REQUIRED,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_10000</prop>
<prop key="insertPromotionEligibilityCriteriaAudienceRec ords*">PROPAGATION_REQUIRED,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_10000</prop>
<prop key="*">PROPAGATION_REQUIRED,-com.biperf.core.exception.ServiceErrorExceptionWit hRollback,timeout_3000</prop>
</props>
</property>
</bean>
============================================
Here's how I have defined the datasource lookup. Notice that I'm using the JndiFactoryObjectBean:
============================================
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
<property name="jndiName"><value>jdbc/datasource-travelsystem</value></property>
</bean>
You can see that the JNDI name is jdbc/datasource-travelsystem. Remember that this works in WebLogic.
============================================
This is the code I have in the WAR file's META-INF/context.xml file that should set up the datasource in Tomcat. I've verified that it exists in Tomcat:
============================================
<Context path="/tosched">
<Resource name="jdbc/datasource-travelsystem" auth="Container"
type="javax.sql.DataSource" username="bitravel" password="l3v9rt1b"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:travel"
maxActive="8" maxIdle="4"/>
I know that the datasource is available because if I use this code in a test servlet:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/datasource-travelsystem");
Connection conn = ds.getConnection();
It doesn't fail.
When I deploy the app to Tomcat 5.5.9, it fails with this error:
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [datasourceContext-server.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
With a stack trace of (abbreviated):
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingConte xt.java:769)
at org.apache.naming.NamingContext.lookup(NamingConte xt.java:152)
at org.apache.naming.SelectorContext.lookup(SelectorC ontext.java:136)
at javax.naming.InitialContext.lookup(InitialContext. java:351)
at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:123)
at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:85)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:121)
at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:71)
at org.springframework.jndi.JndiObjectLocator.lookup( JndiObjectLocator.java:85)
at org.springframework.jndi.JndiObjectFactoryBean.aft erPropertiesSet(JndiObjectFactoryBean.java:124)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:937)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:334)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:271)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:310)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:80)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
at com.biperf.core.utils.ApplicationContextFactory.ge tApplicationContext(ApplicationContextFactory.java :113)
Now, some suggestions on the web have said to include java:comp/env/ somewhere, which I've tried in various places but to no avail. The error message may change, but it still doesn't work.
I've got to believe that somebody has Spring working this way on Tomcat. Can anybody give me some guidance? Since it works on WebLogic I know it's close, I just can't figure out what I need to tweak for Tomcat.
Thank you very much!!!!
Ryan Asleson
Co-Author, "Foundations of Ajax" and "Pro Ajax and Java Frameworks"
Lead Developer, Taconite (http://taconite.sf.net/)


Reply With Quote