Do you have the datasource defined as a <resource-ref> in web.xml?

Jan


On 5 December 2012 03:32, Adam Retter <[email protected]> wrote:

> Hi there,
>
> I have been using the jetty-maven-plugin in combination with the
> maven-failsafe-plugin to start and stop jetty before and after our
> integration tests are executed.
>
> So far this has worked well, however we are trying to move to JNDI for
> our database connections, rather than configuring them directly
> through our Spring  applicationContext.xml
>
> We are using version 8.1.8.v20121106 of the jetty-maven-plugin, and
> even though Jetty appears to start the C3P0 connection pool we define
> in its JNDI connection, when our Web App tries to get a JNDI
> datasource, it always fails with the error:
>
> javax.naming.NameNotFoundException; remaining name 'jdbc/substitute'
>
> The jetty part of our Maven pom.xml looks like this:
>
> <plugin>
>                     <groupId>org.mortbay.jetty</groupId>
>                     <artifactId>jetty-maven-plugin</artifactId>
>                     <configuration>
>                         <scanIntervalSeconds>10</scanIntervalSeconds>
>                         <stopPort>8995</stopPort>
>                         <stopKey>STOP</stopKey>
>                         <contextPath>/</contextPath>
>                         <connectors>
>                             <connector
> implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
>                                 <port>8990</port>
>                                 <maxIdleTime>60000</maxIdleTime>
>                             </connector>
>                         </connectors>
>                         <systemProperties>
>                             <systemProperty>
>                                 <name>substitutes.folder</name>
>                                 <value>target/test/substitutes</value>
>                             </systemProperty>
>                             <systemProperty>
>                                 <name>temp.folder</name>
>                                 <value>target/test/tmp/substitutes</value>
>                             </systemProperty>
>                         </systemProperties>
>
> <jettyConfig>src/test/resources/jetty-config.xml</jettyConfig>
>                     </configuration>
>                     <executions>
>                         <execution>
>                             <id>start-jetty</id>
>                             <phase>pre-integration-test</phase>
>                             <goals>
>                                 <goal>run-exploded</goal>
>                             </goals>
>                             <configuration>
>
> <scanIntervalSeconds>0</scanIntervalSeconds>
>                                 <daemon>true</daemon>
>                             </configuration>
>                         </execution>
>                         <execution>
>                             <id>stop-jetty</id>
>                             <phase>post-integration-test</phase>
>                             <goals>
>                                 <goal>stop</goal>
>                             </goals>
>                         </execution>
>                     </executions>
>                     <dependencies>
>                         <dependency>
>                             <groupId>c3p0</groupId>
>                             <artifactId>c3p0</artifactId>
>                             <version>${c3p0.version}</version>
>                             <scope>runtime</scope>
>                         </dependency>
>                         <dependency>
>                             <groupId>hsqldb</groupId>
>                             <artifactId>hsqldb</artifactId>
>                             <version>1.8.0.10</version>
>                             <scope>runtime</scope>
>                         </dependency>
>                     </dependencies>
>                 </plugin>
>
> The jetty-config.xml file referenced in the pom.xml above looks like this:
>
> <?xml version="1.0"?>
> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
> "http://www.eclipse.org/jetty/configure.dtd";>
> <Configure id="Server" class="org.eclipse.jetty.server.Server">
>
>     <New id="substituteServer"
> class="org.eclipse.jetty.plus.jndi.Resource">
>         <Arg>jdbc/substitute</Arg>
>         <Arg>
>             <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
>                 <Set name="driverClass">org.hsqldb.jdbc.JDBCDriver</Set>
>                 <Set name="jdbcUrl">jdbc:hsqldb:mem:test</Set>
>                 <Set name="user">SA</Set>
>                 <Set name="password"></Set>
>             </New>
>          </Arg>
>     </New>
> </Configure>
>
> When we run 'mvn clean install' and it gets to the failsafe plugin, we
> see the following on the console:
>
> [INFO]
> [INFO] <<< jetty-maven-plugin:8.1.8.v20121106:run-exploded
> (start-jetty) @ substitute-server <<<
> [INFO]
> [INFO] --- jetty-maven-plugin:8.1.8.v20121106:run-exploded
> (start-jetty) @ substitute-server ---
> [INFO] Configuring Jetty for project: substitute-server
> [INFO] Configuring Jetty from xml configuration file =
>
> /home/dev/svn-root/trunk/substitute/substitute-server/src/test/resources/jetty-config.xml
> Dec 4, 2012 4:20:24 PM com.mchange.v2.log.MLog <clinit>
> INFO: MLog clients using java 1.4+ standard logging.
> Dec 4, 2012 4:20:24 PM com.mchange.v2.c3p0.C3P0Registry banner
> INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug?
> true; trace: 10]
> [INFO] Context path = /
> [INFO] Tmp directory =
> /home/dev/svn-root/trunk/substitute/substitute-server/target/tmp
> [INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
> [INFO] Web overrides =  none
> 2012-12-04 16:20:25.070:INFO:oejs.Server:jetty-8.1.8.v20121106
> 2012-12-04 16:20:26.621:INFO:oejpw.PlusConfiguration:No Transaction
> manager found - if your webapp requires one, please configure one.
> Null identity service, trying login service: null
> Finding identity service: null
> 2012-12-04 16:20:36.829:INFO:oejsh.ContextHandler:started
>
> o.m.j.p.JettyWebAppContext{/,file:/home/dev/svn-root/trunk/substitute/substitute-server/target/substitute-server-3.0-SNAPSHOT/},/home/dev/svn-root/trunk/substitute/substitute-server/target/substitute-server-3.0-SNAPSHOT
>
> In the above output I can see that Jetty indeed started up the c3p0
> connection pool, so from that I assume that it should have bound the
> JNDI resource, however as Jetty then starts up our Spring Web App, I
> see the following:
>
> Related cause: org.springframework.beans.factory.BeanCreationException:
> Error creating bean with name 'substituteDataSource': Invocation of
> init method failed; nested exception is
> javax.naming.NameNotFoundException; remaining name 'jdbc/substitute'
>
> The related Spring config looks like:
>
> <jee:jndi-lookup id="substituteDataSource"
> jndi-name="java:comp/env/jdbc/substitute"
> expected-type="javax.sql.DataSource"/>
>
> So my question is, why can spring not bind to the JNDI resource that
> we have setup in Jetty?
>
> Thanks Adam.
>
>
> --
> Adam Retter
>
> skype: adam.retter
> tweet: adamretter
> http://www.adamretter.org.uk
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>



-- 
Jan Bartel <[email protected]>
www.webtide.com – Developer advice, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to