0

I'm struggling with understanding spring framework. I use to work with Java EE.

When I write interfaces and implementations, Can I use annotation on interfaces?

@Repository // Can I do this?
interface MyRepository {
}

@Repository // Can I omit this?
class MyRepositoryImpl implements MyRepository {
}

What about @Service? Is it same?

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
  • http://stackoverflow.com/questions/146391/annotations-on-interfaces .. This is pretty much the same question that you are asking – ArunM Aug 01 '13 at 09:04
  • @ArunM [One of the answer](http://stackoverflow.com/a/146422/330457) is what I wanted to know. Not the question, I think. – Jin Kwon Aug 01 '13 at 09:07
  • [Where to put @Transactional](http://stackoverflow.com/questions/5551541/where-to-put-transactional-in-interface-specification-or-implementation). I second @Bozho answer – Luca Basso Ricci Aug 01 '13 at 09:12

1 Answers1

0

According to Annotation definition we can use annotate interfaces. When we define a interface if that interface defined as @Target({ java.lang.annotation.ElementType.TYPE }) ,

then TYPE can be Class, interface (including annotation type), or enum declaration TYPE according to javadoc.

,

SRy
  • 2,901
  • 8
  • 36
  • 57