How to ignore Exceptions during Spring context initialization?

How to configure Spring to continue load its beans, if one of its defined beans in its init method throwed exception. lazy-init="true" option doesn't help - it is just ignored. In this bean init() method i try to open connection with server, which may fail to load the application spring context. Spring 3.0.6

Answers


The Idea of Exceptions is to fix the cause of them, not to ignore them.

Have that said: I have never seen anything for that: you have to do it by our own. Put a try catch around the init method that consume the exception and log it.

If you have real AspectJ, then you can use it for that task too. But Spring-AOP will not work.


(comment) I use side library where I should call init method, which establish connection with some server, where problem might appear.

In this case. what about a factory that provides the bean which causes the trouble to the context. The factory should check the connection first (or wait for the exception) (what exactly you do is an implementation detail) and return the bean if every thing is correct. If the connection is failing, then the factory return a Dummy implementation instead..


Need Your Help

RRULE google-rfc-2445 with hour and seconds

java jodatime rfc2445 rrule rfc5545

I'm working with the implementation google-rfc-2445 (https://code.google.com/p/google-rfc-2445/) to generate the date which should be repeated following an event, not as a rule indicate (RRULE) tha...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.