3

As Spring has the annotation @Component to represent any Spring manage component. Then again we use @Controller to in a MVC controller bean. But What extra advantage i get use @Controller over @Component? If we use @Controller instead of @Component is it for more clarity on layers or is there any additional support give by Spring?

0

1 Answer 1

0

The @Controller is used specifically used in SpringMVC and indicates that the annotated class has the role of a controller, and this in turn allows the Spring DispatcherServlet to identify potential handlers for requests to the particular service.

When the DispatcherServlet receives a request, it delegates it to the appropriate controller, based on its @RequestMapping and @Controller values.

@Component indicates that the class itself should be managed by the Spring container.

Both are similiar in the fact they are discovered by the classpath scanning.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.