处理Spring语境中的异常

时间:2018-05-25 09:04:43

标签: java spring exception-handling spring-ioc

我如何处理来自Spring 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>

并在主方法中加载上下文

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);
    }
}

假设数据库已关闭。现在我加载上下文异常时没有捕获到catch块。有没有办法解决这个问题?

0 个答案:

没有答案