Sever: Springsource tc server-developer-2.1.0/ tomcat-6.0.29.B
O/S: Windows Vista
I am using Springsource Tool Suite 2.5.1 and tc server 2.1. I am
trying to configure a data source to PostgresSql. I followed the steps
outlined in http://tomcat.apache.org/tomcat-6.0-...tml#PostgreSQL.
1. I tried to add data source resource in
$CATALINA_BASE/conf/Catalina/localhost/<myappcontextfilename>.xml file
similar to the one below. Unfortunately, Springtool suite keeps
overwriting this file and the <Resource name...> definition is lost.
Springsuite overwrites it with <Context docBase.... source=..../>
without resource name definition.
<Context
docBase="C:\springsource\tc-server-developer-2.0.4.RELEASE\spring-insight-instance\wtpwebapps\myapp"
path="/myapp" reloadable="true"
source="org.eclipse.jst.jee.server:myapp">
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/myapp"
username="postgres" password="password" maxActive="20"
maxIdle="10" maxWait="-1"/>
</Context>
2. Then I attempted to define it as a global resource though the
Apache link warns that it some time does not work. The definition is
given below.
<GlobalNamingResources>
<Resource auth="Container"
driverClassName="org.postgresql.Driver" maxActive="20" maxIdle="10"
maxWait="-1" name="jdbc/postgres" password="password"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/myapp" username="postgres"/>
</GlobalNamingResources>
3. Then I add the resource reference in web.xml as below.
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4. But when the spring tc server comes up, it gives the below error.
Nov 13, 2010 10:42:09 PM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
java.sql.SQLException
at
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:201)
at
org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:150)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:619)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:562)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:425)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:130)
at
org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:93)
at
org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:490)
at
org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:219)
at
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:140)
at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at
org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1020)
at
org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:629)
at
org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:237)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4540)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:568)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1282)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:807)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at
org.apache.catalina.core.StandardService.start(StandardService.java:519)
at
org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:195)
... 41 more
Nov 13, 2010 10:42:09 PM
org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException
Nov 13, 2010 10:42:11 PM org.apache.catalina.core.ApplicationContext log
5. Finally I configured the data source using Data Source Explorer. I
set-up with the same parameters as given above in
<GlobalNamingResources>. When I click on Test Connection, I get Ping
Successful message. When I expand the 'jdbc/postgres' connection in
Data Source Explorer, I am able to see myapp database.
6. But when I use the below code snippet to obtain data source, I
still get the error.
System.out.println("before initialcontext");
InitialContext ctx = null;
DataSource ds = null;
try {
ctx = new InitialContext();
System.out.println("after initialcontext");
if ( ctx == null ) {
System.out.println("Uh oh -- no context!");
} else {
System.out.println("Context not null");
}
ds = (DataSource) ctx.lookup(
"java:/comp/env/jdbc/postgres" );
} catch (NamingException nae) {
System.out.println("NAE Message = " + nae.getMessage());
nae.printStackTrace();
}
if ( ds == null ) {
System.out.println("Data source not found!");
} else {
System.out.println("Data source found!");
}
I get the below error.
before initialcontext
after initialcontext
Context not null
NAE Message = null
javax.naming.NamingException
at org.apache.naming.NamingContext.lookup(NamingContext.java:805)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at
com.mybuildingspace.mybuilding.service.delivery.DeliveryServiceImpl.getDeliveryList(DeliveryServiceImpl.java:40)
at
com.mybuildingspace.mybuilding.web.delivery.DeliveryJqgridDataController.handleRequest(DeliveryJqgridDataController.java:27)
at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
......
Data source not found!
7. Please Help! I have been struggling with this for almost 3 days .
Thanks in advance for all your help
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]