diff --git a/spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanBeanPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanBeanPostProcessor.java
deleted file mode 100644
index 7642f66df80..00000000000
--- a/spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanBeanPostProcessor.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.context.scan;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.core.Ordered;
-
-/**
- * A base {@link BeanPostProcessor} implementation that holds the packages to use for a
- * given component. An implementation must implement
- * {@link #postProcessBeforeInitialization(Object, String)} and update the component
- * responsible to manage the packages to scan.
- *
- * @author Phillip Webb
- * @author Oliver Gierke
- * @author Stephane Nicoll
- * @since 1.4.0
- */
-public abstract class AbstractEntityScanBeanPostProcessor
- implements BeanPostProcessor, Ordered {
-
- private final String[] packagesToScan;
-
- protected AbstractEntityScanBeanPostProcessor(String[] packagesToScan) {
- this.packagesToScan = packagesToScan;
- }
-
- /**
- * Return the packages to use.
- * @return the packages to use.
- */
- protected String[] getPackagesToScan() {
- return this.packagesToScan;
- }
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- return bean;
- }
-
- @Override
- public int getOrder() {
- return 0;
- }
-
-}
diff --git a/spring-boot/src/main/java/org/springframework/boot/context/scan/package-info.java b/spring-boot/src/main/java/org/springframework/boot/context/scan/package-info.java
deleted file mode 100644
index c6a135a5978..00000000000
--- a/spring-boot/src/main/java/org/springframework/boot/context/scan/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Support for component scanning.
- */
-package org.springframework.boot.context.scan;
diff --git a/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScan.java b/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScan.java
deleted file mode 100644
index 5f968f92764..00000000000
--- a/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScan.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.neo4j;
-
-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;
-
-import org.neo4j.ogm.annotation.NodeEntity;
-import org.neo4j.ogm.session.SessionFactory;
-
-import org.springframework.context.annotation.Import;
-import org.springframework.core.annotation.AliasFor;
-
-/**
- * Configures the {@link SessionFactory} to scan for Neo4J {@link NodeEntity} classes in
- * the classpath. This annotation provides an alternative to manually setting
- * {@link SessionFactoryProvider#setPackagesToScan(String...)} and is particularly useful
- * if you want to configure entity scanning in a type-safe way, or if your
- * {@link SessionFactory} is auto-configured.
- *
- * A {@link SessionFactoryProvider} must be configured within your Spring
- * ApplicationContext in order to use entity scanning. Furthermore, any existing
- * {@code packagesToScan} setting will be replaced.
- *
- * One of {@link #basePackageClasses()}, {@link #basePackages()} or its alias
- * {@link #value()} may be specified to define specific packages to scan. If specific
- * packages are not defined scanning will occur from the package of the class with this
- * annotation.
- *
- * @author Stephane Nicoll
- * @since 1.4.0
- */
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Import(NodeEntityScanRegistrar.class)
-public @interface NodeEntityScan {
-
- /**
- * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
- * declarations e.g.: {@code @NodeEntityScan("org.my.pkg")} instead of
- * {@code @NodeEntityScan(basePackages="org.my.pkg")}.
- * @return the base packages to scan
- */
- @AliasFor("basePackages")
- String[] value() default {};
-
- /**
- * Base packages to scan for node entities. {@link #value()} is an alias for (and
- * mutually exclusive with) this attribute.
- *
- * Use {@link #basePackageClasses()} for a type-safe alternative to String-based
- * package names.
- * @return the base packages to scan
- */
- @AliasFor("value")
- String[] basePackages() default {};
-
- /**
- * Type-safe alternative to {@link #basePackages()} for specifying the packages to
- * scan for node entities. The package of each class specified will be scanned.
- *
- * Consider creating a special no-op marker class or interface in each package that
- * serves no purpose other than being referenced by this attribute.
- * @return classes from the base packages to scan
- */
- Class>[] basePackageClasses() default {};
-
-}
diff --git a/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScanRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScanRegistrar.java
deleted file mode 100644
index aaa6b6cf5d4..00000000000
--- a/spring-boot/src/main/java/org/springframework/boot/neo4j/NodeEntityScanRegistrar.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.neo4j;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.SmartInitializingSingleton;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.boot.context.scan.AbstractEntityScanBeanPostProcessor;
-import org.springframework.boot.context.scan.AbstractEntityScanRegistrar;
-import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
-import org.springframework.util.Assert;
-
-/**
- * {@link ImportBeanDefinitionRegistrar} used by {@link NodeEntityScan}.
- *
- * @author Stephane Nicoll
- */
-class NodeEntityScanRegistrar extends AbstractEntityScanRegistrar {
-
- NodeEntityScanRegistrar() {
- super(NodeEntityScan.class, "nodeEntityScanBeanPostProcessor",
- NodeEntityScanBeanPostProcessor.class);
- }
-
- /**
- * {@link BeanPostProcessor} to set
- * {@link SessionFactoryProvider#setPackagesToScan(String...)} based on an
- * {@link NodeEntityScan} annotation.
- */
- static class NodeEntityScanBeanPostProcessor extends
- AbstractEntityScanBeanPostProcessor implements SmartInitializingSingleton {
-
- private boolean processed;
-
- NodeEntityScanBeanPostProcessor(String[] packagesToScan) {
- super(packagesToScan);
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- if (bean instanceof SessionFactoryProvider) {
- SessionFactoryProvider provider = (SessionFactoryProvider) bean;
- provider.setPackagesToScan(getPackagesToScan());
- this.processed = true;
- }
- return bean;
- }
-
- @Override
- public void afterSingletonsInstantiated() {
- Assert.state(this.processed,
- "Unable to configure "
- + "SessionFactoryFactoryBean from @NodeEntityScan, "
- + "ensure an appropriate bean is registered.");
- }
-
- }
-
-}
diff --git a/spring-boot/src/main/java/org/springframework/boot/neo4j/SessionFactoryProvider.java b/spring-boot/src/main/java/org/springframework/boot/neo4j/SessionFactoryProvider.java
index 19232849e52..a24214e307a 100644
--- a/spring-boot/src/main/java/org/springframework/boot/neo4j/SessionFactoryProvider.java
+++ b/spring-boot/src/main/java/org/springframework/boot/neo4j/SessionFactoryProvider.java
@@ -25,7 +25,6 @@ import org.neo4j.ogm.session.SessionFactory;
*
* @author Stephane Nicoll
* @since 1.4.0
- * @see NodeEntityScan
*/
public class SessionFactoryProvider {
diff --git a/spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityScanRegistrar.java
similarity index 55%
rename from spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanRegistrar.java
rename to spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityScanRegistrar.java
index 61d026867c2..ba7f04513cd 100644
--- a/spring-boot/src/main/java/org/springframework/boot/context/scan/AbstractEntityScanRegistrar.java
+++ b/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityScanRegistrar.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2016 the original author or authors.
+ * Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,68 +14,45 @@
* limitations under the License.
*/
-package org.springframework.boot.context.scan;
+package org.springframework.boot.orm.jpa;
-import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.ConstructorArgumentValues;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
- * A baseĀ {@link ImportBeanDefinitionRegistrar} used to collect the packages to scan for a
- * given component.
- *
- * Expect to process an annotation type that defines a {@code basePackage} and
- * {@code basePackageClasses} attributes as well as a {@code value} alias of
- * {@code basePackage}.
- *
- * The {@link ImportBeanDefinitionRegistrar} registers a single
- * {@link AbstractEntityScanBeanPostProcessor} implementation with the packages to use.
+ * {@link ImportBeanDefinitionRegistrar} used by {@link EntityScan}.
*
* @author Phillip Webb
* @author Oliver Gierke
- * @author Stephane Nicoll
- * @since 1.4.0
- * @see AbstractEntityScanBeanPostProcessor
+ * @deprecated as of 1.4 along with {@link EntityScan}
*/
-public abstract class AbstractEntityScanRegistrar
- implements ImportBeanDefinitionRegistrar {
+@Deprecated
+class EntityScanRegistrar implements ImportBeanDefinitionRegistrar {
- private final Class extends Annotation> annotationType;
-
- private final String beanPostProcessorName;
-
- private final Class extends AbstractEntityScanBeanPostProcessor> beanPostProcessorType;
-
- /**
- * Create an instance.
- * @param annotationType the annotation to inspect
- * @param beanPostProcessorName the name of the bean post processor
- * @param beanPostProcessorType the type of the bean post processor implementation
- */
- protected AbstractEntityScanRegistrar(Class extends Annotation> annotationType,
- String beanPostProcessorName,
- Class extends AbstractEntityScanBeanPostProcessor> beanPostProcessorType) {
- this.beanPostProcessorName = beanPostProcessorName;
- this.annotationType = annotationType;
- this.beanPostProcessorType = beanPostProcessorType;
- }
+ private static final String BEAN_NAME = "entityScanBeanPostProcessor";
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
Set packagesToScan = getPackagesToScan(importingClassMetadata);
- if (!registry.containsBeanDefinition(this.beanPostProcessorName)) {
+ if (!registry.containsBeanDefinition(BEAN_NAME)) {
addEntityScanBeanPostProcessor(registry, packagesToScan);
}
else {
@@ -83,9 +60,9 @@ public abstract class AbstractEntityScanRegistrar
}
}
- protected Set getPackagesToScan(AnnotationMetadata metadata) {
+ private Set getPackagesToScan(AnnotationMetadata metadata) {
AnnotationAttributes attributes = AnnotationAttributes
- .fromMap(metadata.getAnnotationAttributes(this.annotationType.getName()));
+ .fromMap(metadata.getAnnotationAttributes(EntityScan.class.getName()));
String[] basePackages = attributes.getStringArray("basePackages");
Class>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
Set packagesToScan = new LinkedHashSet();
@@ -103,22 +80,21 @@ public abstract class AbstractEntityScanRegistrar
private void addEntityScanBeanPostProcessor(BeanDefinitionRegistry registry,
Set packagesToScan) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
- beanDefinition.setBeanClass(this.beanPostProcessorType);
+ beanDefinition.setBeanClass(EntityScanBeanPostProcessor.class);
beanDefinition.getConstructorArgumentValues()
.addGenericArgumentValue(toArray(packagesToScan));
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
// We don't need this one to be post processed otherwise it can cause a
// cascade of bean instantiation that we would rather avoid.
beanDefinition.setSynthetic(true);
- registry.registerBeanDefinition(this.beanPostProcessorName, beanDefinition);
+ registry.registerBeanDefinition(BEAN_NAME, beanDefinition);
}
private void updateEntityScanBeanPostProcessor(BeanDefinitionRegistry registry,
Set packagesToScan) {
- BeanDefinition definition = registry
- .getBeanDefinition(this.beanPostProcessorName);
- ConstructorArgumentValues.ValueHolder constructorArguments = definition
- .getConstructorArgumentValues().getGenericArgumentValue(String[].class);
+ BeanDefinition definition = registry.getBeanDefinition(BEAN_NAME);
+ ValueHolder constructorArguments = definition.getConstructorArgumentValues()
+ .getGenericArgumentValue(String[].class);
Set mergedPackages = new LinkedHashSet();
mergedPackages.addAll(Arrays.asList((String[]) constructorArguments.getValue()));
mergedPackages.addAll(packagesToScan);
@@ -129,4 +105,52 @@ public abstract class AbstractEntityScanRegistrar
return set.toArray(new String[set.size()]);
}
+ /**
+ * {@link BeanPostProcessor} to set
+ * {@link LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)} based
+ * on an {@link EntityScan} annotation.
+ */
+ static class EntityScanBeanPostProcessor
+ implements BeanPostProcessor, SmartInitializingSingleton, Ordered {
+
+ private final String[] packagesToScan;
+
+ private boolean processed;
+
+ EntityScanBeanPostProcessor(String[] packagesToScan) {
+ this.packagesToScan = packagesToScan;
+ }
+
+ @Override
+ public Object postProcessBeforeInitialization(Object bean, String beanName)
+ throws BeansException {
+ if (bean instanceof LocalContainerEntityManagerFactoryBean) {
+ LocalContainerEntityManagerFactoryBean factoryBean = (LocalContainerEntityManagerFactoryBean) bean;
+ factoryBean.setPackagesToScan(this.packagesToScan);
+ this.processed = true;
+ }
+ return bean;
+ }
+
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName)
+ throws BeansException {
+ return bean;
+ }
+
+ @Override
+ public void afterSingletonsInstantiated() {
+ Assert.state(this.processed,
+ "Unable to configure "
+ + "LocalContainerEntityManagerFactoryBean from @EntityScan, "
+ + "ensure an appropriate bean is registered.");
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ }
+
}
diff --git a/spring-boot/src/main/java/org/springframework/boot/orm/jpa/JpaEntityScanRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/orm/jpa/JpaEntityScanRegistrar.java
deleted file mode 100644
index d7d9ccdeee1..00000000000
--- a/spring-boot/src/main/java/org/springframework/boot/orm/jpa/JpaEntityScanRegistrar.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2012-2015 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.orm.jpa;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.SmartInitializingSingleton;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.boot.context.scan.AbstractEntityScanBeanPostProcessor;
-import org.springframework.boot.context.scan.AbstractEntityScanRegistrar;
-import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
-import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
-import org.springframework.util.Assert;
-
-/**
- * {@link ImportBeanDefinitionRegistrar} used by {@link EntityScan}.
- *
- * @author Phillip Webb
- * @author Oliver Gierke
- */
-class JpaEntityScanRegistrar extends AbstractEntityScanRegistrar {
-
- JpaEntityScanRegistrar() {
- super(EntityScan.class, "entityScanBeanPostProcessor",
- JpaEntityScanBeanPostProcessor.class);
- }
-
- /**
- * {@link BeanPostProcessor} to set
- * {@link LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)} based
- * on an {@link EntityScan} annotation.
- */
- static class JpaEntityScanBeanPostProcessor extends
- AbstractEntityScanBeanPostProcessor implements SmartInitializingSingleton {
-
- private boolean processed;
-
- JpaEntityScanBeanPostProcessor(String[] packagesToScan) {
- super(packagesToScan);
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- if (bean instanceof LocalContainerEntityManagerFactoryBean) {
- LocalContainerEntityManagerFactoryBean factoryBean = (LocalContainerEntityManagerFactoryBean) bean;
- factoryBean.setPackagesToScan(getPackagesToScan());
- this.processed = true;
- }
- return bean;
- }
-
- @Override
- public void afterSingletonsInstantiated() {
- Assert.state(this.processed,
- "Unable to configure "
- + "LocalContainerEntityManagerFactoryBean from @EntityScan, "
- + "ensure an appropriate bean is registered.");
- }
-
- }
-
-}
diff --git a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScan.java b/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScan.java
deleted file mode 100644
index 0e0b5911d89..00000000000
--- a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScan.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.context.scan;
-
-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;
-
-import org.springframework.context.annotation.Import;
-import org.springframework.core.annotation.AliasFor;
-
-/**
- * EntityScan test annotation.
- *
- * @author Stephane Nicoll
- */
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Import(TestEntityScanRegistrar.class)
-public @interface TestEntityScan {
-
- @AliasFor("basePackages")
- String[] value() default {};
-
- @AliasFor("value")
- String[] basePackages() default {};
-
- Class>[] basePackageClasses() default {};
-
-}
diff --git a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanRegistrar.java b/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanRegistrar.java
deleted file mode 100644
index af86af37df6..00000000000
--- a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanRegistrar.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.context.scan;
-
-import org.springframework.beans.BeansException;
-
-/**
- * Test implementation of {@link AbstractEntityScanRegistrar}.
- *
- * @author Stephane Nicoll
- */
-class TestEntityScanRegistrar extends AbstractEntityScanRegistrar {
-
- static final String BEAN_NAME = "testEntityScanBeanPostProcessor";
-
- TestEntityScanRegistrar() {
- super(TestEntityScan.class, BEAN_NAME, TestEntityScanBeanPostProcessor.class);
- }
-
- static class TestFactoryBean {
- private String[] packagesToScan;
-
- public void setPackagesToScan(String... packagesToScan) {
- this.packagesToScan = packagesToScan;
- }
-
- public String[] getPackagesToScan() {
- return this.packagesToScan;
- }
-
- }
-
- static class TestEntityScanBeanPostProcessor
- extends AbstractEntityScanBeanPostProcessor {
-
- TestEntityScanBeanPostProcessor(String[] packagesToScan) {
- super(packagesToScan);
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- if (bean instanceof TestFactoryBean) {
- TestFactoryBean factoryBean = (TestFactoryBean) bean;
- factoryBean.setPackagesToScan(getPackagesToScan());
- }
- return bean;
- }
-
- }
-
-}
diff --git a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanTests.java b/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanTests.java
deleted file mode 100644
index 7f60ced3f2b..00000000000
--- a/spring-boot/src/test/java/org/springframework/boot/context/scan/TestEntityScanTests.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.context.scan;
-
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import org.springframework.boot.context.scan.TestEntityScanRegistrar.TestFactoryBean;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.AnnotationConfigurationException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.Matchers.containsString;
-
-/**
- * Tests for {@link TestEntityScan}.
- *
- * @author Phillip Webb
- * @author Stephane Nicoll
- */
-public class TestEntityScanTests {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private AnnotationConfigApplicationContext context;
-
- @After
- public void closeContext() {
- if (this.context != null) {
- this.context.close();
- }
- }
-
- @Test
- public void testValue() throws Exception {
- this.context = new AnnotationConfigApplicationContext(ValueConfig.class);
- assertSetPackagesToScan("com.mycorp.entity");
- }
-
- @Test
- public void basePackages() throws Exception {
- this.context = new AnnotationConfigApplicationContext(BasePackagesConfig.class);
- assertSetPackagesToScan("com.mycorp.entity2");
- }
-
- @Test
- public void basePackageClasses() throws Exception {
- this.context = new AnnotationConfigApplicationContext(
- BasePackageClassesConfig.class);
- assertSetPackagesToScan(getClass().getPackage().getName());
- }
-
- @Test
- public void fromConfigurationClass() throws Exception {
- this.context = new AnnotationConfigApplicationContext(FromConfigConfig.class);
- assertSetPackagesToScan(getClass().getPackage().getName());
- }
-
- @Test
- public void valueAndBasePackagesThrows() throws Exception {
- this.thrown.expect(AnnotationConfigurationException.class);
- this.thrown.expectMessage(allOf(containsString("'value'"),
- containsString("'basePackages'"), containsString("com.mycorp.entity"),
- containsString("com.mycorp")));
- this.context = new AnnotationConfigApplicationContext(ValueAndBasePackages.class);
- }
-
- @Test
- public void valueAndBasePackageClassesMerges() throws Exception {
- this.context = new AnnotationConfigApplicationContext(
- ValueAndBasePackageClasses.class);
- assertSetPackagesToScan("com.mycorp.entity", getClass().getPackage().getName());
- }
-
- @Test
- public void basePackageAndBasePackageClassesMerges() throws Exception {
- this.context = new AnnotationConfigApplicationContext(
- BasePackagesAndBasePackageClasses.class);
- assertSetPackagesToScan("com.mycorp.entity2", getClass().getPackage().getName());
- }
-
- @Test
- public void considersMultipleAnnotations() {
- this.context = new AnnotationConfigApplicationContext(MultiScanFirst.class,
- MultiScanSecond.class);
- assertSetPackagesToScan("foo", "bar");
- }
-
- private void assertSetPackagesToScan(String... expected) {
- String[] actual = this.context.getBean(TestFactoryBean.class).getPackagesToScan();
- assertThat(actual).isEqualTo(expected);
- }
-
- @Configuration
- static class BaseConfig {
-
- @Bean
- public TestFactoryBean testFactoryBean() {
- return new TestFactoryBean();
- }
-
- }
-
- @TestEntityScan("com.mycorp.entity")
- static class ValueConfig extends BaseConfig {
-
- }
-
- @TestEntityScan(basePackages = "com.mycorp.entity2")
- static class BasePackagesConfig extends BaseConfig {
-
- }
-
- @TestEntityScan(basePackageClasses = TestEntityScanTests.class)
- static class BasePackageClassesConfig extends BaseConfig {
-
- }
-
- @TestEntityScan
- static class FromConfigConfig extends BaseConfig {
-
- }
-
- @TestEntityScan(value = "com.mycorp.entity", basePackages = "com.mycorp")
- static class ValueAndBasePackages extends BaseConfig {
-
- }
-
- @TestEntityScan(value = "com.mycorp.entity", basePackageClasses = TestEntityScanTests.class)
- static class ValueAndBasePackageClasses extends BaseConfig {
-
- }
-
- @TestEntityScan(basePackages = "com.mycorp.entity2", basePackageClasses = TestEntityScanTests.class)
- static class BasePackagesAndBasePackageClasses extends BaseConfig {
-
- }
-
- @TestEntityScan(basePackages = "foo")
- static class MultiScanFirst extends BaseConfig {
-
- }
-
- @TestEntityScan(basePackages = "bar")
- static class MultiScanSecond extends BaseConfig {
-
- }
-
-}
diff --git a/spring-boot/src/test/java/org/springframework/boot/neo4j/NodeEntityScanTests.java b/spring-boot/src/test/java/org/springframework/boot/neo4j/NodeEntityScanTests.java
deleted file mode 100644
index 5f611bfb4f6..00000000000
--- a/spring-boot/src/test/java/org/springframework/boot/neo4j/NodeEntityScanTests.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2012-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.neo4j;
-
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Tests for {@link NodeEntityScan}.
- *
- * @author Stephane Nicoll
- */
-public class NodeEntityScanTests {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private AnnotationConfigApplicationContext context;
-
- @After
- public void closeContext() {
- if (this.context != null) {
- this.context.close();
- }
- }
-
- @Test
- public void simpleValue() throws Exception {
- this.context = new AnnotationConfigApplicationContext(ValueConfig.class);
- assertSetPackagesToScan("com.mycorp.entity");
- }
-
- @Test
- public void needsSessionFactoryFactory() throws Exception {
- this.thrown.expect(IllegalStateException.class);
- this.thrown.expectMessage("Unable to configure "
- + "SessionFactoryFactoryBean from @NodeEntityScan, "
- + "ensure an appropriate bean is registered.");
- this.context = new AnnotationConfigApplicationContext(
- MissingSessionFactory.class);
- }
-
- private void assertSetPackagesToScan(String... expected) {
- String[] actual = this.context.getBean(TestSessionFactoryProvider.class)
- .getPackagesToScan();
- assertThat(actual).isEqualTo(expected);
- }
-
- @Configuration
- static class BaseConfig {
-
- @Bean
- public SessionFactoryProvider sessionFactoryFactoryBean() {
- return new TestSessionFactoryProvider();
- }
-
- }
-
- @NodeEntityScan("com.mycorp.entity")
- static class ValueConfig extends BaseConfig {
- }
-
- @Configuration
- @NodeEntityScan("com.mycorp.entity")
- static class MissingSessionFactory {
- }
-
- private static class TestSessionFactoryProvider extends SessionFactoryProvider {
-
- private String[] packagesToScan;
-
- @Override
- public void setPackagesToScan(String... packagesToScan) {
- this.packagesToScan = packagesToScan;
- }
-
- public String[] getPackagesToScan() {
- return this.packagesToScan;
- }
-
- }
-
-}
diff --git a/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java b/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java
index 93101b2d1f6..8db0ad6ea32 100644
--- a/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java
+++ b/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.mock;
* @author Phillip Webb
* @author Stephane Nicoll
*/
+@Deprecated
public class EntityScanTests {
@Rule
@@ -94,16 +95,19 @@ public class EntityScanTests {
}
@EntityScan("com.mycorp.entity")
+ @SuppressWarnings("deprecation")
static class ValueConfig extends BaseConfig {
}
@Configuration
@EntityScan("com.mycorp.entity")
+ @SuppressWarnings("deprecation")
static class MissingEntityManager {
}
@Configuration
@EntityScan("com.mycorp.entity")
+ @SuppressWarnings("deprecation")
static class BeanPostProcessorConfiguration {
protected final EntityManagerFactory entityManagerFactory;