Where should @Service annotation be kept? Interface or Implementation?

I'm developing application using Spring. I'm required to use @Service annotation. I've ServiceI and ServiceImpl such that ServiceImpl implements ServiceI. I'm confused here that where should I keep the @Service annotation.

Should I annotate interface or implementation with @Service annotation? What are the differences between these two approaches?


Basically annotations like @Service, @Repository, @Component, etc. they all serve the same purpose:

auto-detection when using annotation-based configuration and classpath scanning.

From my experience I am always using @Service annotation on the interfaces or abstract classes and annotations like @Component and @Repository for their implementation. @Component annotation I am using on those classes which serves basic purposes, simple Spring beans, nothing more. @Repository annotation I am using in the DAO layer, for e.g. if I have to communicate to the database, have some transactions, etc.

So I would suggest to annotate your interface with the @Service and other layers depending on the functionality.

Need Your Help

How to use jquery to show hidden form fields

javascript jquery click

I have three input fields for collecting telephone numbers from users. I display one field and hide the other two. I have placed a link(Add home number) below it and when you user clicks on the lin...

JComboBox modify index using DefaultComboBoxModel

java mysql swing jcombobox

I have created a JComboBox and populated its content from database using DefaultComboBoxModel.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.