-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Charles,

On 3/5/14, 12:07 PM, Charles Richard wrote:
> On Tue, Mar 4, 2014 at 8:57 PM, Neven Cvetkovic 
> <neven.cvetko...@gmail.com>wrote:
> 
>> On Tue, Mar 4, 2014 at 2:56 PM, Charles Richard < 
>> charle...@thelearningbar.com> wrote:
>> 
>>> On Tue, Mar 4, 2014 at 3:17 PM, Christopher Schultz < 
>>> ch...@christopherschultz.net> wrote:
>>>> Can we still use Hibernate in our Spring application if we
>>>>> configure the Data Source through a context.xml?
>>>> 
>>>> Yup. You just need to tell Hibernate that you already have a 
>>>> DataSource. I'm not exactly sure how to do that, but I'm
>>>> confident it can be done. You posted only the DataSource
>>>> configuration itself and it didn't have a name (other than
>>>> the "id"). You'll need to figure out how to get Hibernate to
>>>> use an existing (external) DataSource rather than configuring
>>>> it yourself as you have done.
>>>> 
>>>> I'm really not sure how that could be done either but
>>>> hopefully the
>>> developers here could help me with this.
>>> 
>>> 
>> 
> Hi Neven,
> 
> 
>> Charles,
>> 
>> As Chris pointed out - there are two ways you can get a
>> datasource into your Spring application:
>> 
>> 1) Spring managed resource (datasource) - e.g. C3P0, Tomcat Pool 
>> Datasource, etc... this is the one you've been using. Connection
>> pool is implemented and managed by the Spring container. That
>> usually doesn't register itself with JMX MBeanServer.
>> 
>> You define datasource in the Spring configuration, e.g.
>> 
>> <bean id="myDatasource" ... > ... </bean>
>> 
>> 
>> 2) Tomcat / container managed resource (datasource) - defined by
>> the <Resource> in the Tomcat configuration.
>> 
>> See more details on JNDI entries here 
>> https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
>>
>>
>> 
You will notice there are two ways to configure your resource in Tomcat
>> container:
>> 
>> (a) a global resource, so every deployed application will have
>> access to the same entry, as defined in
>> TOMCAT_DIR/conf/server.xml (b) per application resource, as
>> defined in YOURAPP.war/META-INF/context.xml  (as Chris
>> suggested).
>> 
>> I'm trying to get option (b) to work and I'm getting this error:
> 
> Cannot create JDBC driver of class '' for connect URL 'null' 
> java.lang.NullPointerException

Uh. I hate getting this error. I have honestly never figured out what
the root cause is... the only thing that seems to work is to throw out
the whole <Resource> configuration and start from scratch. I'm fairly
sure it's a typo somewhere. Let's take a look...

> It also seems like Tomcat is not picking up my context.xml. Any
> suggestions?
> 
> My context.xml in /ourpath/META-INF:
> 
> <?xml version="1.0" encoding="UTF-8"?> <Context
> antiJARLocking="true" path="">

Remove the "path" attribute: it's not legal here. If you want your
webapp to be the "root" context, then you need to name it ROOT.war (or
ROOT directory) within your webapps/ directory. Note that case
matters, even on case-insensitive filesystems like fat, ntfs, and hfs.
Do you really need "autiJarLocking"?

> <Resource name="jdbc/ourtest" auth="Container" 
> type="javax.sql.DataSource" initialSize="0"  maxActive="100"
> maxIdle="20" maxWait="10000" mindIdle="0" name="xxx"
> password="xxxxxxxxxxxx" removeAbandoned="true"
> removeAbandonedTimeout="1800" 
> url="jdbc:mysql://xxx.xxx.xxx.xxx/jdbc_testing" /> </Context>

You will need a driverClassName in there. For MySQL, it should be
com.mysql.jdbc.Driver if you are using Connector/J (which, of course,
you are). Note that 1800 seconds is a looooong time.

You have also misspelled "minIdle", though the default for minIdle is
already "0".

> My hibernate-context.xml:
> 
> <?xml version="1.0" encoding="UTF-8"?> <beans
> xmlns="http://www.springframework.org/schema/beans"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> xmlns:jee="http://www.springframework.org/schema/jee"; 
> xsi:schemaLocation="http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
> http://www.springframework.org/schema/jee 
> http://www.springframework.org/schema/jee/spring-jee-2.0.xsd";> 
> .... <jee:jndi-lookup id="dataSource"
> jndi-name="java:comp/env/jdbc/ourtest" />

This I can't help with.

> Relevant section in web.xml:
> 
> <resource-ref> <description>TLB Datasource</description> 
> <res-ref-name>jdbc/ourtest</res-ref-name> 
> <res-type>javax.sql.DataSource</res-type> 
> <res-auth>Container</res-auth> </resource-ref>

This looks fine to me. My experience is that this section in web.xml
is not strictly necessary.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTF3FMAAoJEBzwKT+lPKRY09EQAKf9HWAIyQlEkQoK4GqpVr+w
n5BnPmGsAYXbtF4nRRomPruzx9uDo2RsOMwpooiS4/2AqzGinhFtnpXGQ/fXuQkX
WzCv7FDy//LLlpmd0LeNuWq8hYwtbmP9Cfy9nItT0sBoov3smYYgioIkZc7RQGpG
WrMC4gYo0csQ/ZfMjI+kpMX6fWntckQNWRqvvjOsTJe3lXAAjkZ7kUGzRar3ew32
boyDrNv/Drxh5L2BhLoIJoosnnVNcdptohiVwcMPAyhhIMu/EC2PiMVgk1ilwNmf
1HsjZqpdZaESVGJ9HJhCKVM6NVgfiCG/Mmpq0qyud3tfQCMTGHk6cQCLAk69ttb3
FSAcPQlYIf0/qTopxlTfp8rQ/yRkEBFJVIkPto+2pprxH5QNRu3TMKBsvWUS2Svn
b0tPP5B5mdPGs3N8xTKqY7/QyldrzDTNoBCBy2AOR0QzlFM/zQmquoZ4yZ0vqzXk
JNd+KxqCDMW/VOUpIVByF/HLEPsumqLnXwYe7lXv/GXI+oqB8kD6W2aHX7Wy9fvb
Ruq87zZqyONSQxCK49o4BmJmhxFeLDxdSkInBlfHAFwW7zdy/Y5yTyHTGtqI4iWp
mdJUKDEW0pgocfue7MkEloZfJMrx1ENOBJ/zFRy7S5reeoain63Gq4dCtaswE2df
CJ19j8SaG7sHD2CZtcrz
=DbYM
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to