Viorel, Your approach is interesting. It's only different from mine in one
way: you put your <Context> in
webapp/[your-app]/META-INF/context.xml
but I put mine in
conf/Catalina/localhost/[your-app].xml
Actually I would like your approach better than mine if I could get it to
work, because it would mean that the context config is located in a
predictable sub-path within the webapp folder, rather than an unpredictable
sub-path within the conf folder. Unfortunately though, your approach does
not work on my installation. Can you point me to a page that explains how
to get this to work? I understood that context.xml is used to deploy
webapps using the deployer, rather than configure them once installed. I
have uninstalled all the standard webapps including manager, so the deploy
option is unavailable - do I need it to use context.xml?
I agree that DBCP is pretty easy to configure once you know how. It's just
that I think a lot of people get confused by all the different articles on
the web (and in books, I guess), because the different articles use
different approaches to configuration.
IMHO, whether it is better to configure resources within a webapp <Context>
in server.xml (as described in the how-to docs) or not depends on your
circumstances. I think that putting them under GlobalNamingResources can be
useful, if the server needs to share resources with several webapps, without
each webapp having to configure them separately. I do agree though that if
you want a Resource to belong just to one webapp, it's better NOT to put it
within server.xml at all - its better maintained within the webapp's own
config file. That's just my opinion though :)
> -----Original Message-----
> From: Viorel Dragomir [mailto:[EMAIL PROTECTED]
> Sent: Tuesday 26 October 2004 16:18
> To: Tomcat Users List
> Subject: Re: JNDI DataSource GlobalResources problem
>
>
> Hi
>
> Review current docs from jakarta project regarding jndi config.
> I personally disagree with your conclusion, setting
> server.xml is not such a good idea.
>
> So here what I've done, maybe it will help you.
>
> First set the webapp/[your-app]/META-INF/context.xml
>
> <context .... >
> <Resource name="jdbc/postgres" auth="Container"
> type="javax.sql.DataSource"/>
>
> <ResourceParams name="jdbc/postgres">
>
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
>
> <parameter>
> <name>driverClassName</name>
> <value>org.postgresql.Driver</value>
> </parameter>
>
> <parameter>
> <name>url</name>
> <value>jdbc:postgresql://localhost/database</value>
> </parameter>
>
> <parameter>
> <name>username</name>
> <value>postgres</value>
> </parameter>
>
> <parameter>
> <name>password</name>
> <value/>
> </parameter>
>
> <parameter>
> <name>maxActive</name>
> <value>20</value>
> </parameter>
>
> <parameter>
> <name>maxIdle</name>
> <value>10</value>
> </parameter>
>
> <parameter>
> <name>maxWait</name>
> <value>-1</value>
> </parameter>
>
> <parameter>
> <name>removeAbandoned</name>
> <value>true</value>
> </parameter>
>
> <parameter>
> <name>removeAbandonedTimeout</name>
> <value>60</value>
> </parameter>
>
> <parameter>
> <name>logAbandoned</name>
> <value>true</value>
> </parameter>
> </ResourceParams>
>
> </context>
>
> Now add to webapp/[web-app]/WEB-INF/web.xml
>
> <web-app>
> ....
> <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>
> ...
> </web-app>
>
> I use pg74.215.jdbc2ee.jar located in webapp/[web-app]/WEB-INF/lib/
>
> You can get a connection through Tomcat [don't use main() to
> test this because it won't work] using this kind of code:
>
> ....
> Context initContext = new InitialContext();
> Context envContext =
> (Context)initContext.lookup("java:/comp/env");
> DataSource ds =
> (DataSource)envContext.lookup("jdbc/postgres");
> conn = ds.getConnection();
> ....
>
> I actually think is not so hard to implement it.
> Hope you can use some of this..
> As you can see it was for postgresql and localhost, but you
> can change as you need.
>
>
>
>
> Viorel Dragomir
>
>
>
>
> ----- Original Message -----
> From: Roland Carlsson
> To: TomcatUsers
> Sent: Tuesday, October 26, 2004 17:55
> Subject: Sv: JNDI DataSource GlobalResources problem
>
>
> Thank you very much for your help. I appreciate it very much.
>
> I feel that the GlobalNamingResources is the place to put my
> DataSource-definition since there I can do it one time for
> all web-apps that
> are going to come and go. If there are any change is our
> databases it is one
> place to change. Thats why I ran for that alternative.
>
> I'm looking forward to see the new documentation about DBCP in Tomcat.
>
> Regards
> Roland Carlsson
>
>
> Den 04-10-26 14.58, skrev "Steve Kirk"
> <[EMAIL PROTECTED]>:
>
> >
> > This question illustrates (IMHO) probably the biggest issue
> of confusion
> > with regard to DBCP - that is, there are several XML
> elements that you can
> > potentially use, and several places that you can
> potentially put them.
> > Specifically, the <Resource>, <ResourceParams> and
> <ResourceLink> elements
> > can go in server.xml or your webapp's context config file, and
> > <resource-ref> can go in your web.xml file. Most people
> that have DBCP
> > problems seem to have trouble working out elements to use,
> and where to put
> > them. A quick search on the web shows that this issue is widely
> > misunderstood, and there is lots of misinformation out there.
> >
> > There are actually several possibilities that work. I have
> not chosen the
> > same possibility as you Roland, but hope I can help. The
> how-to pages
> > linked earlier by Shinobu and me are also good points of
> reference, and if
> > you follow them _exactly_ it will work. I belive that the
> simplest and
> > clearest page to follow is this one:
> >
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources
> -howto.html -
> > I think the JDBC page contains at least one slightly
> misleading instruction.
> >
> > To answer your question, yes you have used <resource-ref>
> correctly and your
> > <Resource> and <ResourceParams> elements seem OK.
> >
> > However, note that you have not followed the recommended
> approach in the
> > how-to docs ;) because your <Resource> and <ResourceParams>
> are under
> > <GlobalNamingResources> rather than your webapp's <Context>
> tag. However
> > that does not make it completely wrong. Because they are under
> > <GlobalNamingResources> at the moment, they are not visible
> to your webapp.
> > To fix this, either they need to be moved under <Context>
> as recommended in
> > the how-to, or you need to add a <ResourceLink> under your webapp's
> > <Context> that refers to them.
> >
> > The <Context> that I am referring to should be either under
> <Host> in
> > server.xml as described in the how-to docs, or in your
> webapp's context
> > config file (see my example below).
> >
> > Strictly speaking, according to the JNDI how-to docs, I think your
> > <Resource> tag is not needed because you have a
> <resource-ref>, which is
> > equivalent, and you do not need both. Having said that, I
> have tried it
> > both with and without the <Resource> tag, and both
> approaches work as long
> > as <resource-ref> is in web.xml.
> >
> > For what it's worth, (but not wanting to confuse you!)
> below is the approach
> > that I have working. I'm including this to illustrate that
> there is more
> > than one way to configure DBCP. Note that this is a
> different approach to
> > yours, and also different to that described in the how-to
> docs on the TC
> > site. I took this approach via trial and error because I
> did not find the
> > how-to docs until after I'd got pooling working.
> >
> > 1. I have a <resource-ref> like yours in my
> > CATALINA_HOME\webapps\webapp\WEB-INF\web.xml
> >
> > 2. I created a context config file at
> > CATALINA_HOME\conf\Catalina\localhost\mywebapp.xml, where
> "mywebapp" is the
> > name of the webapp, which contains just my webapp's
> <Context> element,
> > which in turn contains <Resource> and <ResourceParams> very
> similar to
> > yours. That this <Context> tag is more usually included in
> server.xml,
> > under the default localhost <Host> tag. (By default your
> server.xml will
> > not include a <Context> tag for your webapp, you have to
> add it inside the
> > Context element for your webapp, or inside a DefaultContext
> element for the
> > surrounding <Host> or <Engine> element, as described in the
> JNDI how-to
> > page. The entire contents of my context config file are below:
> >
> > <?xml version='1.0' encoding='utf-8'?>
> > <Context docBase="C:\jakarta-tomcat-5.0.27\webapps\mywebapp"
> > path="/mywebapp" reloadable="true">
> > <ResourceParams name="jdbc/mywebapp">
> > <parameter>
> > <name>factory</name>
> >
> > <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > </parameter>
> > ... more parameters like yours ...
> > </ResourceParams>
> > </Context>
> >
> > 3. I have no <ResourceLink> anywhere - I don't need it
> because I have not
> > used <GlobalNamingResources>
> >
> > I know that this is a long-winded reply, but this is a
> tricky area and easy
> > to get confused. I've also been meaning to post this to
> the list for a few
> > months, having spent days learning it. Hope this helps you
> and others :)
> >
> >> -----Original Message-----
> >> From: Roland Carlsson [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday 26 October 2004 12:09
> >> To: TomcatUsers
> >> Subject: Sv: JNDI DataSource GlobalResources problem
> >>
> >>
> >> Hello!
> >>
> >> Thanks for your answer. I have no ResourceLink in my
> configuration. I
> >> understand that I should put it a <Context>-tag but not where.
> >>
> >> How does this affect the configuration I already have done?
> >> Is the use of
> >> resource-ref and Resource correct?
> >>
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]