1

How can i handle exceptions from Spring context . Consider the context

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="URL" value="jdbc:oracle:thin:@localhost:1521/xe" />
    <property name="user" value="abc" />
    <property name="password" value="abc" />    
</bean>

<bean id="abc" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="default" />
    <property name="persistenceXmlLocation" value="classpath*:META-INF/abc-persistence.xml" />
</bean>

And am loading context in main method

public static void main(String[] args) {
    ApplicationContext  applicationContext = null;
    try {
        applicationContext = new ClassPathXmlApplicationContext("/META-INF/spring/test.xml");
    } catch (Exception e) {
        System.out.println("Exception caugtht " + e);
    }
}

Lets say database is down .now when i load context exceptions are not caught in catch block. Is there any way to handle this ?

Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52
nanpakal
  • 971
  • 3
  • 18
  • 37

0 Answers0