in your webapp WEB-INF/web.xml you will need to define the ContextLoaderListener
then you will also need a way to define the root context

if you want to locate the parameters in your applicationContext.xml try
<!--
  - Loads the root application context of this web app at startup,
  - by default from "/WEB-INF/applicationContext.xml".
 - Note that you need to fall back to Spring's ContextLoaderServlet for
 - J2EE servers that do not follow the Servlet 2.4 initialization order.
  - Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
  - to access it anywhere in the web application, outside of the framework.
  - The root context is the parent of all servlet-specific contexts.
- This means that its beans are automatically available in these child contexts,
  - both for getBean(name) calls and (external) bean references.
  -->
<listener>
 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- This will display The root application context
  - Location of the XML file that defines the root application context.
  - Applied by ContextLoaderServlet.
- Can be set to "/WEB-INF/applicationContext-hibernate.xml" for the Hibernate implementation,
- "/WEB-INF/applicationContext-ojb.xml" for the Apache OJB one,
 - "/WEB-INF/applicationContext-toplink.xml" for the Oracle TopLink one,
 - or "/WEB-INF/applicationContext-jdbc.xml" for the JDBC one.
  -->
<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/applicationContext-jdbc.xml</param-value>
 <!--
 <param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
 <param-value>/WEB-INF/applicationContext-ojb.xml</param-value>
 <param-value>/WEB-INF/applicationContext-toplink.xml</param-value>
  -->
</context-param>

Does this help?
Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- From: "Glen Vermeylen" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Wednesday, April 25, 2007 10:07 AM
Subject: Re: Can't create jdbc resource in context.xml


It also doesn't work with the resource-ref element. The error was ""
javax.naming.NameNotFoundException: Name jdbc is not bound in this
Context"",
but I was able to lookup the jdbc/sandwiches datasource using programmatic
jndi lookup.
Weird part is that everything works fine if I move the datasource element
from the context file to server.xml. Is it possible that the realm gets
initialized before the datasource or that something causes the realm to
initialize in a different context where it doesn't have access to the
datasource?

Anyways, thank you very much for your help. I've found a solution which
works but if there are some suggestions on how to get it to work using a
datasourcerealm I will still try them out.

Regards,
Glen.


2007/4/23, Rashmi Rubdi <[EMAIL PROTECTED]>:

Hi Glen,

I compared your configuration with the standard configuration
mentioned
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
and found a few differences.

Please see my replies to your post below:

On 4/20/07, Glen Vermeylen <[EMAIL PROTECTED]> wrote:
> Hello everybody,
>
> I'm trying to move a global jdbc resource out of server.xml so it is
> application specific. Following is the server.xml (which works fine)
.................................
>
> What I did was remove the the <GlobalNamingResources> and <Realm >
elements
> from server.xml and put them inside
> $CATALINA_HOME/conf/Catalina/localhost/esandwich.xml (don't mind the
weird
> name :) ), but I keep getting the error
> "javax.naming.NameNotFoundException: Name jdbc is not bound in this
Context"
>
> esandwich.xml:
> <Context docBase="c:/workspace/esandwich/WebContent/" reloadable="true"
> crosscontext="true">

crossContext attribute's case needs to be crossContext , but it is
specified as crosscontext.

One question, though a little irrelevant is -- do you really need
crossContext="true" ? Just because it is specified in the sample on
the JDBC Datasource HowTo page, doesn't mean you would need it - this
is just a thought. If you don't need it, please set it to false or
remove the attribute.

>     <Resource name="jdbc/sandwiches" auth="Container" driverClassName="
> com.mysql.jdbc.Driver"
>         password="tomcat" type="javax.sql.DataSource"
>
url="jdbc:mysql://192.168.16.39:3306/sandwiches?autoReconnect=true"
>         username="tomcat" />
>
>
>     <Realm className="org.apache.catalina.realm.DataSourceRealm"
>         dataSourceName="jdbc/sandwiches" debug="99" roleNameCol="role"
>         userCredCol="password" userNameCol="user"
userRoleTable="userroles"
>         userTable="users" />
> </Context>
>
> I believe the problem lies witht he <Resource> element

No the problem is in web.xml , I don't see any definition for:

<resource-ref>

please see under "3. web.xml configuration" at

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
for the details on web.xml entries.

> because if only move
> the <realm> element to the esandwich.xml and leave the
> <GlobalNamingResources><Resource.....></...> in server.xml everything
still
> works. We've been searching for a few hours now and can't find the
solution.
> Any help would be highly appreciated.
>
> web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app id="WebApp_ID" version="2.4"
>     xmlns="http://java.sun.com/xml/ns/j2ee";
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>
>     <display-name>esandwich</display-name>
>     <listener>
>         <listener-class>
>             org.springframework.web.context.ContextLoaderListener
>         </listener-class>
>     </listener>
>     <servlet>
>         <servlet-name>dispatcher</servlet-name>
>         <servlet-class>
>             org.springframework.web.servlet.DispatcherServlet
>         </servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>dispatcher</servlet-name>
>         <url-pattern>/app/*</url-pattern>
>     </servlet-mapping>
>     <welcome-file-list>
>         <welcome-file>index.jsp</welcome-file>
>     </welcome-file-list>
>     <login-config>
>         <auth-method>FORM</auth-method>
>         <form-login-config>
>             <form-login-page>/login.html</form-login-page>
>             <form-error-page>/loginError.html</form-error-page>
>         </form-login-config>
>     </login-config>
>
>     <security-constraint>
>         <web-resource-collection>
>             <web-resource-name>default</web-resource-name>
>             <url-pattern>/app/*</url-pattern>
>             <http-method>POST</http-method>
>             <http-method>GET</http-method>
>         </web-resource-collection>
>         <auth-constraint>
>             <description>everyone can log in</description>
>             <role-name>*</role-name>
>         </auth-constraint>
>     </security-constraint>
>
>     <security-role>
>         <description>The Only Secure Role</description>
>         <role-name>admin</role-name>
>     </security-role>
>
> </web-app>
>
>
> Many thanks in advance,
> Glen.
>

-Regards
Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to