Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jetty-maven-plugin v8, failsafe and JNDI failure

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


On 5 December 2012 03:32, Adam Retter <adam.retter@xxxxxxxxxxxxxx> 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:



The jetty-config.xml file referenced in the pom.xml above looks like this:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <New id="substituteServer" class="">
            <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>

When we run 'mvn clean install' and it gets to the failsafe plugin, we
see the following on the console:

[INFO] <<< jetty-maven-plugin:8.1.8.v20121106:run-exploded
(start-jetty) @ substitute-server <<<
[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 =
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- [built 21-May-2007 15:04:56; debug?
true; trace: 10]
[INFO] Context path = /
[INFO] Tmp directory =
[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

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"

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
jetty-users mailing list

Jan Bartel <janb@xxxxxxxxxxx> – Developer advice, services and support
from the Jetty & CometD experts.

Back to the top