Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 671577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:23:22+00:00 2026-05-14T00:23:22+00:00

I think this is a pretty basic question, but after Googling around I can’t

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:23:22+00:00Added an answer on May 14, 2026 at 12:23 am

    I think you are going to need to pass in a different type to the consumer (assuming you want to log errors in the constructor of CollectorConsumer) which is a wrapper around the actual construction of the collectorResponder object. i.e. contains a method like

    CollectorResponder create() throws whatever
    

    which is called by your consumer constructor. This wrapper object would be incredibly similar to your factory code but would not be understood by spring. Otherwise, those exceptions are going to happen before your consumer constructor code ever runs no matter what. Spring is not going to be able to inject exceptions, and proxys around an incredibly lazy creation object are unlikely to work without some kind of method call.

    I’m assuming that you don’t just want to log the exceptions in the responderFactory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is a pretty basic question, but here it is anyway. I
I'm afraid this question is pretty basic, but I think it's relevant to a
Okay at first I thought this would be pretty straightforward. But I can't think
This may be a basic question but I am pretty new to DDD. I
okay this might be a pretty lame and basic question but its stuck in
I know this is a pretty basic question, but I don't know how to
I know this is a pretty basic question, and I think I know the
I think this is a pretty basic question. I am currently writing a file
I am new to WCF so I think this is pretty basic. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.