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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:36:47+00:00 2026-05-14T03:36:47+00:00

When moving to Spring 2.5.x I found that it adds more stereotype annotations (on

  • 0

When moving to Spring 2.5.x I found that it adds more stereotype annotations (on top of @Repository from 2.0): @Component, @Service and @Controller. How do you use them? Do you rely on implicit Spring support or you define custom stereotype specific functions/aspects/features? Or is it predominately for marking beans (compile time, conceptual, etc.)?

  • 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-14T03:36:47+00:00Added an answer on May 14, 2026 at 3:36 am

    The following stereotype annotations in 2.5 can be used in a Spring MVC application as an alternative to wiring the beans in XML:

    • @Repository – for DAO beans – allows
      you to throw DataAccessException when
      the data source is not available.

    • @Service – for business beans –
      are fairly simple beans that have some
      default retention policies set up.

    • @Controller – for servlets –
      allows you to set up page request
      mappings, etc.

    In addition, a generic fourth annotation has been introduced: @Component. All of the MVC annotations are specialisations of this one, and you can even use @Component on it’s own, though by doing this in Spring MVC, you will not make use of any future optimisations/functionality added to the higher-level annotations. You can also extend @Component to create your own custom stereotypes.

    Here is a quick example of the MVC annotations in action… First, the data access object:

    @Repository
    public class DatabaseDAO {
        @Autowired
        private SimpleJdbcTemplate jdbcTemplate;
    
        public List<String> getAllRecords() {
            return jdbcTemplate.queryForObject("select record from my_table", List.class);
        }
    }
    

    The service:

    @Service
    public class DataService {
        @Autowired
        private DatabaseDAO database;
    
        public List<String> getDataAsList() {
            List<String> out = database.getAllRecords();
            out.add("Create New...");
            return out;
        }
    }
    

    And finally, the controller:

    @Controller("/index.html")
    public class IndexController {
        @Autowired
        private DataService dataService;
    
        @RequestMapping(method = RequestMethod.GET)
        public String doGet(ModelMap modelMap) {
            modelMap.put(dataService.getDataAsList());
            return "index";
        }
    }
    

    I found this article very good for giving a broad overview of the stereotype annotations, in addition to the official documentation.

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

Sidebar

Related Questions

I'm moving an application to use the Spring3 framework and I have code that
I really like to use spring stereotype annotated beans in spring MVC apps and
I am moving to Eclipse from VS. For me it is much more rich
I have a class that's currently inheriting from Dictionary and then adds a few
Spring Roo can be use in existing projects that follow standard maven layout .
I am moving properties from inside my Spring config file to a separate properties
I have an action from a controller that provides a result variable via $this->set('found_products',
Im moving from django to pylons, is there an admin app?
I'm moving a large wordpress mysql db (1.49gb) from an old server to a
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but

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.