001/*
002 * Copyright 2012-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 *      http://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.boot.autoconfigure.domain;
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.context.annotation.Import;
026import org.springframework.core.annotation.AliasFor;
027
028/**
029 * Configures the base packages used by auto-configuration when scanning for entity
030 * classes.
031 * <p>
032 * Using {@code @EntityScan} will cause auto-configuration to:
033 * <ul>
034 * <li>Set the
035 * {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)
036 * packages scanned} for JPA entities.</li>
037 * <li>Set the packages used with Neo4J's {@link org.neo4j.ogm.session.SessionFactory
038 * SessionFactory}.</li>
039 * <li>Set the
040 * {@link org.springframework.data.mapping.context.AbstractMappingContext#setInitialEntitySet(java.util.Set)
041 * initial entity set} used with Spring Data
042 * {@link org.springframework.data.mongodb.core.mapping.MongoMappingContext MongoDB},
043 * {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext
044 * Cassandra} and
045 * {@link org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext
046 * Couchbase} mapping contexts.</li>
047 * </ul>
048 * <p>
049 * One of {@link #basePackageClasses()}, {@link #basePackages()} or its alias
050 * {@link #value()} may be specified to define specific packages to scan. If specific
051 * packages are not defined scanning will occur from the package of the class with this
052 * annotation.
053 *
054 * @author Phillip Webb
055 * @since 1.4.0
056 * @see EntityScanPackages
057 */
058@Target(ElementType.TYPE)
059@Retention(RetentionPolicy.RUNTIME)
060@Documented
061@Import(EntityScanPackages.Registrar.class)
062public @interface EntityScan {
063
064        /**
065         * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
066         * declarations e.g.: {@code @EntityScan("org.my.pkg")} instead of
067         * {@code @EntityScan(basePackages="org.my.pkg")}.
068         * @return the base packages to scan
069         */
070        @AliasFor("basePackages")
071        String[] value() default {};
072
073        /**
074         * Base packages to scan for entities. {@link #value()} is an alias for (and mutually
075         * exclusive with) this attribute.
076         * <p>
077         * Use {@link #basePackageClasses()} for a type-safe alternative to String-based
078         * package names.
079         * @return the base packages to scan
080         */
081        @AliasFor("value")
082        String[] basePackages() default {};
083
084        /**
085         * Type-safe alternative to {@link #basePackages()} for specifying the packages to
086         * scan for entities. The package of each class specified will be scanned.
087         * <p>
088         * Consider creating a special no-op marker class or interface in each package that
089         * serves no purpose other than being referenced by this attribute.
090         * @return classes from the base packages to scan
091         */
092        Class<?>[] basePackageClasses() default {};
093
094}