I think this is a pretty basic question, but after Googling around I can't seem to find the answer.
What I need is a way to log some custom output with log4j during Spring bean construction. I have a factory class called ResponderFactory
(being used as an instance factory in Spring) with a factory method that can throw 2 different types of exception.
public CollectorResponder collectorResponder(String inputQueueName) throws ConfigurationException, BrokerConnectionException {}
Now, normally I could wrap a call to this method in a try-catch block with 2 catch clauses to handle the logging situations for each of the exceptions. However, if I'm using Spring to inject this CollectorResponder
, created with the factory, into another class I don't see how this is possible.
<bean id="responderFactory" class="com.package.ResponderFactory">
<constructor-arg index="0" ref="basicDispatcher" />
<constructor-arg index="1" value="http://localhost:9000" />
</bean>
<bean id="collectorResponder"
class="com.package.CollectorResponder"
factory-bean="responderFactory" factory-method="collectorResponder">
<constructor-arg value="collector.in" />
</bean>
<bean id="collectorConsumer" class="com.package.CollectorConsumer">
<constructor-arg ref="collectorResponder" />
</bean>
Again, I want to catch these exceptions when the collectorResponder
bean is instantiated. Right now I'm dealing with this is CollectorConsumer
when I instantiate using new CollectorResponder(...)
.
Is there any way I can do this?