2013-08-01 46 views
0

我正在努力理解spring框架。我使用Java EE进行工作。我可以在界面上使用弹簧注释吗?

当我编写接口和实现时,我可以在接口上使用注释吗?

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

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

@Service怎么样?它是一样的吗?

+0

http://stackoverflow.com/questions/146391/annotations-on-interfaces。这是一个很值得你要求 – ArunM

+0

@ArunM [一个答案(HTTP同样的问题: //stackoverflow.com/a/146422/330457)是我想知道的。不是我想的问题。 –

+0

[把@Transactional放在哪里](http://stackoverflow.com/questions/5551541/where-to-put-transactional-in-interface-specification-or-implementation)。我第二@Bozho的答案 –

回答

0

根据Annotation定义,我们可以使用注释接口。当我们定义如果该接口定义为@Target({ java.lang.annotation.ElementType.TYPE }),一个接口

然后TYPE可以根据javadocClass, interface (including annotation type), or enum declaration TYPE

相关问题