diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 204b3962000b..965f06e84a5a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.data.annotation.Persistent; import org.springframework.data.neo4j.core.DatabaseSelectionProvider; import org.springframework.data.neo4j.core.Neo4jClient; import org.springframework.data.neo4j.core.Neo4jOperations; @@ -42,6 +43,7 @@ import org.springframework.data.neo4j.core.convert.Neo4jConversions; import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.schema.RelationshipProperties; import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; import org.springframework.data.neo4j.repository.config.Neo4jRepositoryConfigurationExtension; import org.springframework.transaction.PlatformTransactionManager; @@ -76,7 +78,8 @@ public Neo4jConversions neo4jConversions() { @ConditionalOnMissingBean public Neo4jMappingContext neo4jMappingContext(ApplicationContext applicationContext, Neo4jConversions neo4jConversions) throws ClassNotFoundException { - Set> initialEntityClasses = new EntityScanner(applicationContext).scan(Node.class); + Set> initialEntityClasses = new EntityScanner(applicationContext).scan(Node.class, Persistent.class, + RelationshipProperties.class); Neo4jMappingContext context = new Neo4jMappingContext(neo4jConversions); context.setInitialEntitySet(initialEntityClasses); return context; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java index 5206a3ca5ada..8fd1314d2b6e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java @@ -19,6 +19,11 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNode; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNonAnnotated; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestPersistent; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestRelationshipProperties; import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; @@ -29,6 +34,7 @@ import org.springframework.data.neo4j.core.Neo4jOperations; import org.springframework.data.neo4j.core.Neo4jTemplate; import org.springframework.data.neo4j.core.convert.Neo4jConversions; +import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.ReactiveTransactionManager; @@ -137,6 +143,17 @@ void shouldReuseExistingTransactionManager() { .hasBean("myCustomTransactionManager")); } + @Test + void shouldFilterInitialEntityScanWithKnownAnnotations() { + this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> { + Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class); + assertThat(mappingContext.hasPersistentEntityFor(TestNode.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestPersistent.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestRelationshipProperties.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestNonAnnotated.class)).isFalse(); + }); + } + @Configuration(proxyBeanMethods = false) static class CustomDatabaseSelectionProviderConfiguration { @@ -147,4 +164,10 @@ DatabaseSelectionProvider databaseSelectionProvider() { } + @Configuration(proxyBeanMethods = false) + @TestAutoConfigurationPackage(TestPersistent.class) + static class EntityScanConfig { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveDataAutoConfigurationTests.java index 69096db96252..a107a8128118 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jReactiveDataAutoConfigurationTests.java @@ -21,6 +21,11 @@ import reactor.test.StepVerifier; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNode; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestNonAnnotated; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestPersistent; +import org.springframework.boot.autoconfigure.data.neo4j.scan.TestRelationshipProperties; import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; @@ -30,6 +35,7 @@ import org.springframework.data.neo4j.core.ReactiveNeo4jClient; import org.springframework.data.neo4j.core.ReactiveNeo4jOperations; import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate; +import org.springframework.data.neo4j.core.mapping.Neo4jMappingContext; import org.springframework.transaction.ReactiveTransactionManager; import org.springframework.transaction.TransactionManager; @@ -121,6 +127,17 @@ void shouldUseExistingReactiveTransactionManager() { .hasSingleBean(TransactionManager.class)); } + @Test + void shouldFilterInitialEntityScanWithKnownAnnotations() { + this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> { + Neo4jMappingContext mappingContext = context.getBean(Neo4jMappingContext.class); + assertThat(mappingContext.hasPersistentEntityFor(TestNode.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestPersistent.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestRelationshipProperties.class)).isTrue(); + assertThat(mappingContext.hasPersistentEntityFor(TestNonAnnotated.class)).isFalse(); + }); + } + @Configuration(proxyBeanMethods = false) static class CustomReactiveDatabaseSelectionProviderConfiguration { @@ -131,4 +148,10 @@ ReactiveDatabaseSelectionProvider databaseNameProvider() { } + @Configuration(proxyBeanMethods = false) + @TestAutoConfigurationPackage(TestPersistent.class) + static class EntityScanConfig { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNode.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNode.java new file mode 100644 index 000000000000..50293f98b833 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNode.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; + +@Node +public class TestNode { + + @Id + @GeneratedValue + private Long id; + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNonAnnotated.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNonAnnotated.java new file mode 100644 index 000000000000..c754c3877503 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestNonAnnotated.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; + +public class TestNonAnnotated { + + @Id + @GeneratedValue + private Long id; + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestPersistent.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestPersistent.java new file mode 100644 index 000000000000..54aee30b7b14 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestPersistent.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.autoconfigure.data.neo4j.scan; + +import org.springframework.data.annotation.Persistent; +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; + +@Persistent +public class TestPersistent { + + @Id + @GeneratedValue + private Long id; + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestRelationshipProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestRelationshipProperties.java new file mode 100644 index 000000000000..dbd848694283 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/scan/TestRelationshipProperties.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2020 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 + * + * https://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.autoconfigure.data.neo4j.scan; + +import org.springframework.data.neo4j.core.schema.RelationshipProperties; + +@RelationshipProperties +public class TestRelationshipProperties { + +}