@Component vs @Repository vs @Service in Spring Framework

0 votes

Can someone explain the difference between @Component, @Repository, and @Service annotations? Can we use them interchangeably or do they affect the behavior and the functionality of a class in specific ways?

May 29, 2018 in Java by v.liyyah
• 1,300 points
700 views

1 answer to this question.

0 votes

As you might be knowing, all these three annotations are used for auto bean detection via classpath scan in Spring framework.

If you ask for there differences, there is technically no difference between them. But still, you can’t use them interchangeably as every auto component scan annotation should be used for a special purpose and within the defined layer. Below I have elaborated all three of them:

@Component: It is a basic auto component scan annotation which indicates that an annotated class is an auto scan component.

@Repository: You need to use this annotation within the persistence layer that acts like database repository.

@Service: It indicates that an annotated class is a Service component of the business layer.

answered May 29, 2018 by geek.erkami
• 2,320 points

Related Questions In Java

0 votes
1 answer
0 votes
1 answer

Constructor injection vs Setter injection in Spring Framework

Here, I have listed down few differences. ...READ MORE

answered Aug 29, 2018 in Java by anto.trigg4
• 3,420 points
259 views
0 votes
1 answer

Configuration metadata in Spring Framework

Configuration metadata can be provided to Spring container in ...READ MORE

answered Aug 2, 2018 in Java by code.reaper12
• 3,450 points
838 views
0 votes
1 answer

Types of IOC containers in Spring Framework

There are basically two types of IOC ...READ MORE

answered Aug 27, 2018 in Java by misc.edu04
• 1,380 points
182 views
0 votes
1 answer
0 votes
1 answer

Autowired field pointing NULL in Spring

The field annotated @Autowired is null because ...READ MORE

answered Jun 6, 2018 in Java by avi
• 160 points
4,297 views
0 votes
1 answer

Annotation wiring in Spring

By default, Annotation wiring is not turned ...READ MORE

answered Jul 3, 2018 in Java by code.reaper12
• 3,450 points
70 views
0 votes
1 answer

SuppressWarnings (“unchecked”) in Java

@SuppressWarnings("unchecked") is used when Java generics just don't ...READ MORE

answered Sep 4, 2018 in Java by anto.trigg4
• 3,420 points
65 views
0 votes
1 answer

@Autowired annotation in Spring Framework

The @Autowired annotation provides more accurate control over where ...READ MORE

answered Aug 2, 2018 in Java by geek.erkami
• 2,320 points
98 views
0 votes
1 answer

Types of transaction management in Spring Framework

Well there are basically to types of ...READ MORE

answered Nov 27, 2018 in Java by geek.erkami
• 2,320 points
202 views