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
3,671 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,680 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 30, 2018 in Java by anto.trigg4
• 3,440 points
3,235 views
0 votes
1 answer

Configuration metadata in Spring Framework

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

answered Aug 3, 2018 in Java by code.reaper12
• 3,500 points
12,571 views
0 votes
1 answer

Types of IOC containers in Spring Framework

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

answered Aug 28, 2018 in Java by misc.edu04
• 1,450 points
26,677 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

edited Mar 4, 2022 by Sarfaraz 14,479 views
0 votes
1 answer

Annotation wiring in Spring

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

answered Jul 4, 2018 in Java by code.reaper12
• 3,500 points
1,168 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,440 points
8,927 views
0 votes
1 answer

@Autowired annotation in Spring Framework

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

answered Aug 3, 2018 in Java by geek.erkami
• 2,680 points
1,776 views
0 votes
1 answer

Types of transaction management in Spring Framework

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

answered Nov 28, 2018 in Java by geek.erkami
• 2,680 points
1,932 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP