Hi,
We are trying to configure a datasource in tomcat. The datasource is configured properly as we are able to lookup using simple code in JSP as below :
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------Code:<%@ page import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" %> <% Hashtable env = new Hashtable(); Context ctx = new InitialContext(env); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/cmpPubPoolTest"); out.print("data source is "+ ds); %>
This prints the data source object.
Now the problem is to lookup this datasource from spring.
The configuration in spring is :
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------Code:<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiEnvironment"> <props> <prop key="java.naming.factory.initial">org.apache.naming.java.javaURLContextFactory</prop> <prop key="java.naming.factory.url.pkgs">org.apache.naming</prop> </props> </property> <property name="jndiName"><value>java:comp/env/jdbc/cmpPubPool</value></property> </bean>
Tried with and without specifying the jndiEnvironment , but we get the below error.
I ended up with the below error.
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------Code:applicationContext-hibernate.xml]: Error setting property values; nested exception is PropertyAccessExceptionsException (1 errors) Caused by: PropertyAccessExceptionsException (1 errors) org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.apache.tomcat.dbcp.dbcp.BasicDataSource] to required type [org.springframework.jdbc.datasource.DriverManagerDataSource] for property 'dataSource'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(Pr opertyTypeConverter.java:209) at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(Pr opertyTypeConverter.java:108) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrappe rImpl.java:723) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrappe rImpl.java:575) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(A bstractPropertyAccessor.java:49) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues( AbstractPropertyAccessor.java:68) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues( AbstractPropertyAccessor.java:57) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:792) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.populateBean(AbstractAutowireCapableBeanFactory.java:572) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:415) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:241) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:152) at org.springframework.beans.factory.support.DefaultListableBeanFactory. preInstantiateSingletons(DefaultListableBeanFactory.java:253) at org.springframework.context.support.AbstractApplicationContext.refres h(AbstractApplicationContext.java:331) at org.springframework.web.context.support.AbstractRefreshableWebApplica tionContext.refresh(AbstractRefreshableWebApplicationContext.java:155) at org.springframework.web.context.ContextLoader.createWebApplicationCon text(ContextLoader.java:246) at org.springframework.web.context.ContextLoader.initWebApplicationConte xt(ContextLoader.java:184) at org.springframework.web.context.ContextLoaderListener.contextInitiali zed(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContex t.java:3729) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4 187) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase .java:759) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:73 9) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav a:904) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j ava:867) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474 ) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java :310) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl eSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021) at org.apache.catalina.core.StandardHost.start(StandardHost.java:718) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442 ) at org.apache.catalina.core.StandardService.start(StandardService.java:4 50) at org.apache.catalina.core.StandardServer.start(StandardServer.java:709 ) at org.apache.catalina.startup.Catalina.start(Catalina.java:551) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432) Jul 17, 2007 11:58:50 AM org.apache.catalina.core.StandardContext start SEVERE: Error listenerStart Jul 17, 2007 11:58:50 AM org.apache.catalina.core.StandardContext start SEVERE: Context [/cmpWeb2] startup failed due to previous errors
The context.xml is kept in webapp/myApp/META-INF with the below :
--------------------------------------------------------------------------------------------------------------------------------------------Code:<?xml version="1.0" encoding="UTF-8"?> <Context reloadable="true"> <Resource auth="Container" name="jdbc/cmpPubPool" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" password="cmppub" maxIdle="2" maxWait="5000" username="cmppub" url="jdbc:oracle:thin:@172.20.51.125:1521:cmp" maxActive="4" /> <ResourceLink name="jdbc/cmpPubPool" type="javax.sql.DataSource" global="jdbc/cmpPubPool"/> <Logger name="tc_log" path="logs/mytomcat.log" verbosityLevel = "INFORMATION" /> </Context>
The web.xml is configured as below:
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------Code:<resource-ref> <res-ref-name>jdbc/cmpPubPool</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Am i doing something wrong or Is it a bug in spring ?? Kindly help me.
Regards
Sandeep![]()


Reply With Quote
