Results 1 to 4 of 4

Thread: JNDI Datasource unavailable at application startup causing problems

  1. #1
    Join Date
    Mar 2006
    Location
    Maarssen, The Netherlands
    Posts
    19

    Default JNDI Datasource unavailable at application startup causing problems

    Hi,

    I have a JNDI Datasource with a (non required) database behind it. This Database is sometimes offline. This causes an exception on startup and my application is not started, because of this exception.

    Is there a way to specify that the datasource is not required on startup, so that I can always startup my application?

    Of course, I am aware that I have to catch exceptions when calling the datasource at a later time in my application, but I already handled that, because the database already goes down sometimes after my application started up.

    Thanks in advance!

    Theo Gülcher
    Last edited by gulcher; Jun 18th, 2007 at 04:04 AM.

  2. #2
    Join Date
    Jun 2007
    Posts
    18

    Default

    hello,
    though i'm a newbie myself, hope this would help u.
    u can use this instead of jndi in cases where datasource is not already present

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">

    <property name="driverClassName" value="${driverName}"/>
    <property name="url" value="${yoururl}"/>
    <property name="username" value="${yourUsername}"/>
    <property name="password" value="${yourPassword}"/>
    </bean>
    let, u r using mysql, then it would be
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">

    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost:3306/${YourDb}</value>
    </property>
    <!-- Provide username and password for mysql -->
    <property name="username" value="root"/>
    <property name="password" value=""/>


    </bean>

  3. #3
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    64

    Default

    Did you try lazy-init attribute for your datasource bean? can you provide exception that you get on it?

  4. #4
    Join Date
    Mar 2006
    Location
    Maarssen, The Netherlands
    Posts
    19

    Default

    mpetrashev: your lazy-init suggestion gave me the information I needed to get the solution myself. lazy-init is not available on jee:jndi-lookup tags....but.....

    the datasource should specify the 'lookup-on-startup' attribute with value false.

    Like this:
    Code:
        <!-- Data source for Adam -->
        <jee:jndi-lookup id="adamDataSource" jndi-name="jdbc/adam" resource-ref="true" proxy-interface="javax.sql.DataSource" lookup-on-startup="false"/>
    NB jee:jndi-lookup tag is available from Spring 2.0. Don't forget to add the following bold text on top of your bean XML:
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            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
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    NB proxy-interface="javax.sql.DataSource" is required when setting the cache or lookup-on-startup attribute! This is mentioned when starting up without the proxy-interface attribute added.... ;-)
    Last edited by gulcher; Jun 18th, 2007 at 08:15 AM. Reason: NB Spring 2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •