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 025import org.springframework.core.annotation.AliasFor; 026 027/** 028 * Indicates that an annotated class is a "Repository", originally defined by 029 * Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage, 030 * retrieval, and search behavior which emulates a collection of objects". 031 * 032 * <p>Teams implementing traditional Java EE patterns such as "Data Access Object" 033 * may also apply this stereotype to DAO classes, though care should be taken to 034 * understand the distinction between Data Access Object and DDD-style repositories 035 * before doing so. This annotation is a general-purpose stereotype and individual teams 036 * may narrow their semantics and use as appropriate. 037 * 038 * <p>A class thus annotated is eligible for Spring 039 * {@link org.springframework.dao.DataAccessException DataAccessException} translation 040 * when used in conjunction with a {@link 041 * org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor 042 * PersistenceExceptionTranslationPostProcessor}. The annotated class is also clarified as 043 * to its role in the overall application architecture for the purpose of tooling, 044 * aspects, etc. 045 * 046 * <p>As of Spring 2.5, this annotation also serves as a specialization of 047 * {@link Component @Component}, allowing for implementation classes to be autodetected 048 * through classpath scanning. 049 * 050 * @author Rod Johnson 051 * @author Juergen Hoeller 052 * @since 2.0 053 * @see Component 054 * @see Service 055 * @see org.springframework.dao.DataAccessException 056 * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor 057 */ 058@Target({ElementType.TYPE}) 059@Retention(RetentionPolicy.RUNTIME) 060@Documented 061@Component 062public @interface Repository { 063 064 /** 065 * The value may indicate a suggestion for a logical component name, 066 * to be turned into a Spring bean in case of an autodetected component. 067 * @return the suggested component name, if any (or empty String otherwise) 068 */ 069 @AliasFor(annotation = Component.class) 070 String value() default ""; 071 072}