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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:53+00:00 2026-06-13T00:29:53+00:00

I am reading the book Pro Spring 3 . It has a certain paragraph

  • 0

I am reading the book Pro Spring 3. It has a certain paragraph that really confused me. The paragraph is about autowiring in spring. Here is an excerpt:

In most cases, the answer to the question of whether you should use
autowiring is definitely “no!” Autowiring can save you time in small
applications, but in many cases, it leads to bad practices and is
inflexible in large applications. Using byName seems like a good
idea, but it may lead you to give your classes artificial property
names so that you can take advantage of the autowiring functionality.
The whole idea behind Spring is that you can create your classes how
you like and have Spring work for you, not the other way around …

… For any nontrivial application, steer clear of autowiring at all
costs.

I have always been using the @Autowired tag in applications I have created. Can someone explain what is wrong with it and what I should use instead?

A mini example on how I handle most things now is:

@Service("snippetService")
public class SnippetService {

    @Autowired
    private TestService testService;

    public Snippet getSnippet() {
        return testService.getSnippet();
    }
}    

Is using autowiring like this “wrong” or am I missing something?

  • 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-13T00:29:54+00:00Added an answer on June 13, 2026 at 12:29 am

    I believe there are two things confused here. What is meant by ‘autowiring’ in this chapter is marking bean for automated detection and injection of dependencies. This can be achieved through setting of “autowire” bean attribute.

    This is in fact opposed to using @Autowired where you explicitely indicate field or setter for dependency injection.

    Have a look here: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-autowire.

    To explain it, assume you have

    public class SnippetService {
    
        private TestService testService;
    
        public Snippet getSnippet() {
            return testService.getSnippet();
        }
    
        public void setTestService(TestService testService) {
          this.testService = testService;
        }
    }
    

    If you defined a bean:

    <bean class="mypackage.SnippetService" autowire="byType"/>
    

    spring would attempt to inject bean of matching type, TestService in this case, by calling setTestService setter. Even though you did not use @Autowired. This indeed is dangerous since some setters might not be meant to be called by spring.

    If you set autowire=”no”, nothing will be injected unless marked so with @Autowired, @Resource, @Inject.

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

Sidebar

Related Questions

Recently, I was reading book about Erlang which has hot deployment feature. The deployment
I'm reading Pro JPA 2. The book talks begins by talking about ORM in
Reading a book about C# I noticed that sometimes is mentioned value type and
After reading Steven Sanderson's book Pro ASP.NET MVC I am convinced about the benefits
I am reading the Pro Spring 2.5 book and I have a question to
I am reading the Pro Spring 2.5 book and in chapter 4 they talk
I'm reading a book about C# ( Pro C# and the .NET 4 Platform
I'm reading book about php, and here is task to print elements of array
I was messing about with reset after reading stuff in the Pro Git book.
After reading a book on LINQ I'm thinking about re-writing a mapper class that

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.