【问题标题】:Can I use spring annotations on interfaces?我可以在接口上使用spring注解吗?
【发布时间】:2013-08-02 02:28:36
【问题描述】:

我正在努力理解 Spring 框架。我曾经使用 Java EE。

我写接口和实现的时候,可以在接口上使用注解吗?

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

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

@Service 呢?一样吗?

【问题讨论】:

标签: spring annotations


【解决方案1】:

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

那么TYPE根据javadoc可以是Class, interface (including annotation type), or enum declaration TYPE

,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多