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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:45:01+00:00 2026-05-19T04:45:01+00:00

I have an abstract base class that I use for services which includes the

  • 0

I have an abstract base class that I use for services which includes the implementation of various methods, and a single abstract method. I have some closely related entities that I would like to manage within a single service, so I plan to have that service be a composition of anonymous implementations of the the abstract base service for those entities. I would like to inject the Dao implementation into the anonymous service implementation. I attempted to do something like this.

@Configurable
@Service( value="compositeService" )
public class CompositeServiceImpl 
    extends BaseDataServiceAbstract<AnotherEntity, Long>
    implements CompositeService
{
    BaseDataServiceAbstract<MyObject, Long> myObjectService = 
        new BaseDataServiceAbstract<MyObject, Long>() {

        @Resource( name="myObjectDao")
        BaseDao<MyObject, Long> myObjectDao;

        @Override
        public BaseDao<MyObject, Long> getDao()
        {
            return myObjectDao;
        }
    };

    // other implementation methods and stuff
}

If I do it that way, the Dao does not get injected. If I move the dao out into the containing class, then it works fine. I’m ok with leaving it in the containing class, but wondering what it would take to inject it into the anonymous class implementation.

  • 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-19T04:45:02+00:00Added an answer on May 19, 2026 at 4:45 am

    As long as you call new yourself, Spring doesn’t instantiate the class and therefore won’t be able to inject the dependencies.

    And since you can’t create anonymous classes without calling the default constructor yourself using new, there is no way Spring can help you here.

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

Sidebar

Related Questions

I have a abstract base C# class with a couple of methods that has
Suppose I have an abstract base class, that just defines a container on which
I have an abstract base class, which I use as a base for my
I have a base class that has an abstract getType() method. I want subclasses
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a abstract base class that I have many inherited classes coming off
Ok so I have an abstract base class called Product, a KitItem class that
If I have a base class such that public abstract class XMLSubscription <T extends
I have an abstract base class which acts as an interface. I have two
I have an abstract base class called Shape from which both Circle and Rectangle

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.