001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.stereotype; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025/** 026 * Indicate that the annotated element represents a stereotype for the index. 027 * 028 * <p>The {@code CandidateComponentsIndex} is an alternative to classpath 029 * scanning that uses a metadata file generated at compilation time. The 030 * index allows retrieving the candidate components (i.e. fully qualified 031 * name) based on a stereotype. This annotation instructs the generator to 032 * index the element on which the annotated element is present or if it 033 * implements or extends from the annotated element. The stereotype is the 034 * fully qualified name of the annotated element. 035 * 036 * <p>Consider the default {@link Component} annotation that is meta-annotated 037 * with this annotation. If a component is annotated with {@link Component}, 038 * an entry for that component will be added to the index using the 039 * {@code org.springframework.stereotype.Component} stereotype. 040 * 041 * <p>This annotation is also honored on meta-annotations. Consider this 042 * custom annotation: 043 * <pre class="code"> 044 * package com.example; 045 * 046 * @Target(ElementType.TYPE) 047 * @Retention(RetentionPolicy.RUNTIME) 048 * @Documented 049 * @Indexed 050 * @Service 051 * public @interface PrivilegedService { ... } 052 * </pre> 053 * 054 * If the above annotation is present on a type, it will be indexed with two 055 * stereotypes: {@code org.springframework.stereotype.Component} and 056 * {@code com.example.PrivilegedService}. While {@link Service} isn't directly 057 * annotated with {@code Indexed}, it is meta-annotated with {@link Component}. 058 * 059 * <p>It is also possible to index all implementations of a certain interface or 060 * all the subclasses of a given class by adding {@code @Indexed} on it. 061 * 062 * Consider this base interface: 063 * <pre class="code"> 064 * package com.example; 065 * 066 * @Indexed 067 * public interface AdminService { ... } 068 * </pre> 069 * 070 * Now, consider an implementation of this {@code AdminService} somewhere: 071 * <pre class="code"> 072 * package com.example.foo; 073 * 074 * import com.example.AdminService; 075 * 076 * public class ConfigurationAdminService implements AdminService { ... } 077 * </pre> 078 * 079 * Because this class implements an interface that is indexed, it will be 080 * automatically included with the {@code com.example.AdminService} stereotype. 081 * If there are more {@code @Indexed} interfaces and/or superclasses in the 082 * hierarchy, the class will map to all their stereotypes. 083 * 084 * @author Stephane Nicoll 085 * @since 5.0 086 */ 087@Target(ElementType.TYPE) 088@Retention(RetentionPolicy.RUNTIME) 089@Documented 090public @interface Indexed { 091}