diff --git a/spring-context-indexer/spring-context-indexer.gradle b/spring-context-indexer/spring-context-indexer.gradle index 2b68cd8a51..c4a46b05cc 100644 --- a/spring-context-indexer/spring-context-indexer.gradle +++ b/spring-context-indexer/spring-context-indexer.gradle @@ -4,5 +4,6 @@ dependencies { testCompile(project(":spring-context")) testCompile("javax.inject:javax.inject:1") testCompile("javax.annotation:javax.annotation-api:1.3.2") + testCompile("javax.transaction:javax.transaction-api:1.3") testCompile("org.eclipse.persistence:javax.persistence:2.2.0") } diff --git a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java index 8026d86a07..c8791a53ad 100644 --- a/spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java +++ b/spring-context-indexer/src/main/java/org/springframework/context/index/processor/TypeHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -17,6 +17,7 @@ package org.springframework.context.index.processor; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; @@ -110,7 +111,12 @@ class TypeHelper { } public List getAllAnnotationMirrors(Element e) { - return this.env.getElementUtils().getAllAnnotationMirrors(e); + try { + return this.env.getElementUtils().getAllAnnotationMirrors(e); + } + catch (Throwable ex) { + return Collections.emptyList(); + } } } diff --git a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java index c31486b3a9..dabdaf736f 100644 --- a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java +++ b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java @@ -25,6 +25,7 @@ import javax.persistence.Converter; import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.MappedSuperclass; +import javax.transaction.Transactional; import org.junit.Before; import org.junit.Rule; @@ -44,6 +45,7 @@ import org.springframework.context.index.sample.SampleRepository; import org.springframework.context.index.sample.SampleService; import org.springframework.context.index.sample.cdi.SampleManagedBean; import org.springframework.context.index.sample.cdi.SampleNamed; +import org.springframework.context.index.sample.cdi.SampleTransactional; import org.springframework.context.index.sample.jpa.SampleConverter; import org.springframework.context.index.sample.jpa.SampleEmbeddable; import org.springframework.context.index.sample.SampleEmbedded; @@ -67,6 +69,7 @@ import static org.springframework.context.index.processor.Metadata.*; * Tests for {@link CandidateComponentsIndexer}. * * @author Stephane Nicoll + * @author Vedran Pavic */ public class CandidateComponentsIndexerTests { @@ -142,6 +145,11 @@ public class CandidateComponentsIndexerTests { testSingleComponent(SampleNamed.class, Named.class); } + @Test + public void cdiTransactional() { + testSingleComponent(SampleTransactional.class, Transactional.class); + } + @Test public void persistenceEntity() { testSingleComponent(SampleEntity.class, Entity.class); diff --git a/spring-context-indexer/src/test/java/org/springframework/context/index/sample/cdi/SampleTransactional.java b/spring-context-indexer/src/test/java/org/springframework/context/index/sample/cdi/SampleTransactional.java new file mode 100644 index 0000000000..909a61a6a2 --- /dev/null +++ b/spring-context-indexer/src/test/java/org/springframework/context/index/sample/cdi/SampleTransactional.java @@ -0,0 +1,28 @@ +/* + * Copyright 2002-2019 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.context.index.sample.cdi; + +import javax.transaction.Transactional; + +/** + * Test candidate for {@link Transactional}. + * + * @author Vedran Pavic + */ +@Transactional +public class SampleTransactional { +}