package org.springframework.stereotype;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates that an annotated class is a "Service", originally defined by Domain-Driven
* Design (Evans, 2003) as "an operation offered as an interface that stands alone in the
* model, with no encapsulated state."
*
* <p>May also indicate that a class is a "Business Service Facade" (in the Core J2EE
* patterns sense), or something similar. This annotation is a general-purpose stereotype
* and individual teams may narrow their semantics and use as appropriate.
*
* <p>This annotation serves as a specialization of {@link Component @Component},
* allowing for implementation classes to be autodetected through classpath scanning.
*
* @author Juergen Hoeller
* @since 2.5
* @see Component
* @see Repository
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Service {
/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any
*/
String value() default "";
}
@Service
注解:
- 在类上 使用该注解,表示其是一个
Service
- 最初由领域驱动设计(
Domain-Driven Design(Evans,2003)
)定义为“作为接口提供的操作,该操作在模型中独立存在,没有封装状态 - 可能还表明某个类是“业务服务门面”(就核心J2EE模式而言),或类似的内容
- 该注解是
@Component
注解的一个专业化的注解 - 允许通过类路径扫描自动检测实现类
默认方法value()
:
- 返回值类型是
String
类型 - 无参数,
value
默认值是空 - 该值可能表示对逻辑组件名称的建议