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