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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:26:11+00:00 2026-06-13T22:26:11+00:00

I know it is not a best design but just a thought from a

  • 0

I know it is not a best design but just a thought from a Spring newbie.

Now we can easily autowire any service method to each other conveniently in Spring framework. But What is the disadvantage to create a static factory method of the service class and call it everywhere?

It’s pretty common like this:

@Autowired
CustomerService customerService;

....
AccountDetail ad = customerService.getAccountDetail(accountId, type);

But this should work too:

// If we make getAccountDetail(String, String) static:
AccountDetail ad = CustomerService.getAccountDetail(accountId, type);

So why there is a design like autowire? It looks fancy and really cool, but the work behind this is still create one service bean instance on another service object.

Seriously while Spring is all over the market so many posts and articles are talking about pros & renovations. But is it guaranteeing better performance(like using autowire instead of static)?

  • 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-13T22:26:12+00:00Added an answer on June 13, 2026 at 10:26 pm

    There are numerous reasons:

    • you can’t replace CustomerService with a mock easily during tests (tools like PowerMock aside)

    • static methods do not participate in standard, proxy-based AOP (no transactions, security, custom aspects)

    • you can no longer use fancy injection techniques, like injecting HTTP request (request scoped) into singleton scoped services (poor design anyway, but…)

    But to be complete, there are also advantages:

    • static method is actually closer to your intent, Spring beans are very rarely stateful, thus they don’t really need an instance to work

    • static call might be faster (this is irrelevant in 99% of the programs)

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

Sidebar

Related Questions

I know this sort of code is not best practice, but nevertheless in certain
I know a little bit of regex, but not mutch. What is the best
So I know NSManagedObjects are not thread safe, and the best way to get
I know that SQL Server does not have boolean data type and your best
In an ASP.Net WAP, the home page /default.aspx is receiving periodic requests from I-know-not-where.
I do not know how to ask this question. So I will just give
Excuse the title, but it's best I just explain the problem. I have 2
Ok, so this may not be the best design decision, and I don't really
What's the best way to design/use my model and NSFetchedResultsController so that I can
Yes, I know, the old question of the best web framework ... but let

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.