001/*
002 * Copyright 2012-2016 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.mapping.CassandraMappingContext Cassandra}
044 * and {@link org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext
045 * Couchbase} mapping contexts.</li>
046 * </ul>
047 * <p>
048 * One of {@link #basePackageClasses()}, {@link #basePackages()} or its alias
049 * {@link #value()} may be specified to define specific packages to scan. If specific
050 * packages are not defined scanning will occur from the package of the class with this
051 * annotation.
052 *
053 * @author Phillip Webb
054 * @since 1.4.0
055 * @see EntityScanPackages
056 */
057@Target(ElementType.TYPE)
058@Retention(RetentionPolicy.RUNTIME)
059@Documented
060@Import(EntityScanPackages.Registrar.class)
061public @interface EntityScan {
062
063        /**
064         * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
065         * declarations e.g.: {@code @EntityScan("org.my.pkg")} instead of
066         * {@code @EntityScan(basePackages="org.my.pkg")}.
067         * @return the base packages to scan
068         */
069        @AliasFor("basePackages")
070        String[] value() default {};
071
072        /**
073         * Base packages to scan for entities. {@link #value()} is an alias for (and mutually
074         * exclusive with) this attribute.
075         * <p>
076         * Use {@link #basePackageClasses()} for a type-safe alternative to String-based
077         * package names.
078         * @return the base packages to scan
079         */
080        @AliasFor("value")
081        String[] basePackages() default {};
082
083        /**
084         * Type-safe alternative to {@link #basePackages()} for specifying the packages to
085         * scan for entities. The package of each class specified will be scanned.
086         * <p>
087         * Consider creating a special no-op marker class or interface in each package that
088         * serves no purpose other than being referenced by this attribute.
089         * @return classes from the base packages to scan
090         */
091        Class<?>[] basePackageClasses() default {};
092
093}