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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:34:01+00:00 2026-05-20T14:34:01+00:00

Does it makes sense in Spring to use @Autowired to wire directly to a

  • 0

Does it makes sense in Spring to use @Autowired to wire directly to a concrete class and not to an interface (and make use of ‘by type’ autowiring)

If a class doesn’t implements an interface wouldn’t it be better to instantiate it via constructor or a factory (keeping things simple); rather than make it a Spring bean just for the heck of it.

  • 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-20T14:34:01+00:00Added an answer on May 20, 2026 at 2:34 pm

    Does it makes sense in Spring to use @Autowired to wire directly to a concrete class and not to an interface

    Sure. The practice of autowiring is independent of what you’re autowiring. It’ll work with classes just as well as interfaces.

    However, whether or not it’s a good idea is debatable, although this is a more general question of whether you should always introduce an interface for a given class, rather than talk directly to the class type. The benefits include easier unit-testing and a cleaner design, at the expense of code clutter.

    There’s another good reason to autowire interface types rather than class types, which is that if Spring needs to generate a proxy object around the bean before injecting it, then if the bean’s class defines any interfaces, then the proxy will implement those interfaces, and will not be type-compatible with the bean class itself. If you then try and autowire that bean by class type, it will fail. The easiest way to avoid this annoying scenario is to always autowire by interface type, that way it will lways work as you expect.

    and make use of ‘by type’ autowiring

    If you mean container-level byType autowiring, then you don’t want to do that. It’s the old Spring 1.x style of autowiring, and it’s highly inflexibile (see limitations of autowiring).

    Stick with @Autowired, it’s much more flexible and easier to control.

    If a class doesn’t implements an interface wouldn’t it be better to instantiate it via constructor or a factory (keeping things simple); rather than make it a Spring bean just for the heck of it.

    The two questions are completely separate. An object should be made a Spring bean if you need Spring to control its dependencies and lifecycle, regardless of whether or not it implements interfaces. If you find that the object has no dependencies, and no meaningful interface, then perhaps there is no reason to make it a bean.

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

Sidebar

Related Questions

does it make sense to use an Filecache when using Sqlite as Database ?
Does it make sense to use RIA Services as a service provider to an
Does this make sense? MyValue can be true or false Should it not be
When does it make sense to use Loop fission/distribution if I am compiling for
Does it make sense to use shell_qoute from String::ShellQuote when I pass the arguments
Does it makes sense that when columns of a datagridview are cleared, all rows
Does it make sense to create a constant for the value of a penny?
Does it make sense that if the Text on a TextBox is databound to
Does it make sense to obsfucate Javascript? The only clear benefits I can see
Does it make sense to simply copy the mysql\data files vs mysql replication between

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.