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 7836497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:11:07+00:00 2026-06-02T14:11:07+00:00

I have a class B which implements W interface. It has a default implementation

  • 0

I have a class B which implements W interface. It has a default implementation of W’s method. class C and D override default implementation for which they need a service whose bean is instantiated by spring. String a and b comes from user and hence there is no way I can create a bean of B/C/D in advance. So I have a factory which creates a new object based on user parameters (it will create B/C/D based on parameters). Is there any clean way I can use service beans(aa/bb/cc/dd etc.) from inside C and D (spring autowires during server startup, at that time parameter required for instantiating B/C/D are not available) or is there any better way to solve the problem ?

 Class B implements W{
      String a;
      String b;
      B (String a, String b);

      w_method(){

      }
   }

    Class C extends B {
      @Autowired
      Service aa;

      @Autowired
      Service bb;

      @Autowired
      Service cc;

      @override
      w_method(){
      }
    }

Class D extends B {
  @Autowired
  Service dd;

  @override
  w_method(){
  }
}
  • 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-06-02T14:11:08+00:00Added an answer on June 2, 2026 at 2:11 pm

    I think the simplest method would be to wire the services into the factory and call setters on the B / C / D objects before you return them, rather than attempting to use @Autowired.

    Or use axtavt’s constructor argument method. If you want to avoid depending on ApplicationContext, you can use Lookup Method Injection, but you’ll have to patch Spring per this blog post: http://nurkiewicz.blogspot.co.uk/2010/08/creating-prototype-spring-beans-on.html

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

Sidebar

Related Questions

I have a class Data which implements Serializable interface. This class has such fields
I have a public class which has the following method and instance variable: public
If I have a class which has an interface definition like below; public class
I have a superclass which implements the Comparable Interface and overrides the compareTo() method.
I have a class which implements the following interface: IUser { string UserName {
I have a business object class BusinessObject which implements an interface IAlternateInterface. I already
I have a generic interface IConstrained which is implemented by the generic Constrained class.
I am new to Android and Java programming. I have a class which implements
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I have a factory class, DocumentLoaderFactory , which simply returns an instance that implements

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.