This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes How to catch Datasource exception during Spring initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply locked New topic
Author

How to catch Datasource exception during Spring initialization

J Mahayni
Greenhorn

Joined: Jan 03, 2006
Posts: 7
I am interested in catching an exception during Spring initialization but I am not sure of how to do so. What I am looking for is A WAY to catch this exception should it occur again in the future (i.e.: how and where), so that I can inform the user of what have happened.

I am using Spring to initialize a datasource in the applicationContext.xml as below:
"
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/ITLM</value>
</property>
</bean>
"

I am getting the following exception that I already resolved but want to capture it for future "setup" occurrance:

"The following exception was logged org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: Context: servers/server1, name: jdbc/ITLM: First component in name ITLM not found.
Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0"

I thought of using ServletContextListener but was not sure of how to capture an exception in the contextInitialized() method? I may need a different approach altogether?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  43
Welcome to JavaRanch.

You might profitably read this, which states that you should post your question to one forum, and one forum only. Application Frameworks seems a much better fit, so I'm closing the thread here.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to catch Datasource exception during Spring initialization
 
Similar Threads
Spring + Struts [1 web app / 2 ApplicationContext]
Datasource exception during Spring initialization
How to catch Datasource exception during Spring initialization
Configuration of 2 Databases using spring
handling ContextSource & DataSource Transaction using @Transactional annotation.