0

What will happen if we interchange various annotations like @Service, @Controller and @Repository? I know its the best practice to follow to represent the spring component with these annotations but what happen if we are not doing so ?

  • What do you mean? What would you use instead? Only `@Component` or programmatically registering beans? – João Dias Nov 01 '21 at 19:03
  • Check this: https://stackoverflow.com/questions/6827752/whats-the-difference-between-component-repository-service-annotations-in Basically they are both captured as beans, but are intercepted differently, for example @Repository has an extra layer for exception translation – Bahij.Mik Nov 01 '21 at 19:03

1 Answers1

0

Basically @Component is a generic annotation stereotype and @Service, @Repository and @Controller are just subtypes with a more semantic meaning, at the end of the day with these annotation you are just registering a bean in the spring container and if you exchange those annotations you application is going to work as good as before.

Of course if you have a JpaRepository implementation for example you want to use @Repository annotation instead of @Controller, just for mentioning an example.