1

以下は For Component Interface のソースコードです

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Component {

Spring Controller アノテーションの場合は以下のとおりです。

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

@Component が Controller アノテーションに追加されるのはなぜですか? その目的は何ですか?この行を削除するとどうなりますか?

カスタム注釈の作成に使用される以下の注釈タイプについては明確です。

@Documented Whether to put the annotation in Javadocs
@Retention  When the annotation is needed
@Target     Places the annotation can go    
@Inherited  Whether subclasses get the annotation
4

2 に答える 2

4

@Controllerは( 、など@Componentのよう@Serviceに) です。@Repository@Endpoint

ここでは @Component がメタアノテーションとして使用されているため、コンポーネントスキャンを使用して取得できます。その次に @Controller は、いくつかの追加機能を持つ特別なコンポーネントです (Spring MVC がそれを処理します)。@Component アノテーションを削除すると、 component-scan はそれを検出できなくなります。

@Component独自の注釈を作成して配置するだけで、独自の注釈を作成することもできます@Component

于 2013-11-11T17:18:40.670 に答える