spring - Where should @Service annotation be kept? Interface or Implementation? -
i'm developing application using spring. i'm required use @service annotation. i've servicei , serviceimpl such serviceimpl implements servicei. i'm confused here should keep @service annotation.
should annotate interface or implementation @service annotation? differences between these 2 approaches?
basically annotations @service, @repository, @component, etc. serve same purpose:
auto-detection when using annotation-based configuration , classpath scanning.
from experience using @service annotation on interfaces or abstract classes , annotations @component , @repository implementation. @component annotation using on classes serves basic purposes, simple spring beans, nothing more. @repository annotation using in dao layer, e.g. if have communicate database, have transactions, etc.
so suggest annotate interface @service , other layers depending on functionality.
Comments
Post a Comment