Browse Source

Revised indexer implementation

Issue: SPR-11890
pull/1296/merge
Juergen Hoeller 8 years ago
parent
commit
d96738d613
  1. 30
      spring-context/src/main/java/org/springframework/stereotype/Indexed.java
  2. 5
      spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java

30
spring-context/src/main/java/org/springframework/stereotype/Indexed.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -24,21 +24,21 @@ import java.lang.annotation.Target; @@ -24,21 +24,21 @@ import java.lang.annotation.Target;
/**
* Indicate that the annotated element represents a stereotype for the index.
* <p>
* The {@code CandidateComponentsIndex} is an alternative to classpath
*
* <p>The {@code CandidateComponentsIndex} is an alternative to classpath
* scanning that uses a metadata file generated at compilation time. The
* index allows retrieving the candidate components (i.e. fully qualified
* name) based on a stereotype. This annotation instructs the generator to
* index the element on which the annotated element is present or if it
* implements or extends from the annotated element. The stereotype is the
* fully qualified name of the annotated element.
* <p>
* Consider the default {@link Component} annotation that is meta-annotated
*
* <p>Consider the default {@link Component} annotation that is meta-annotated
* with this annotation. If a component is annotated with {@link Component},
* an entry for that component will be added to the index using the
* {@code org.springframework.stereotype.Component} stereotype.
* <p>
* This annotation is also honored on meta-annotations. Consider this
*
* <p>This annotation is also honored on meta-annotations. Consider this
* custom annotation:
* <pre class="code">
* package com.example;
@ -50,13 +50,15 @@ import java.lang.annotation.Target; @@ -50,13 +50,15 @@ import java.lang.annotation.Target;
* &#064;Service
* public @interface PrivilegedService { ... }
* </pre>
* If this annotation is present on an type, it will be indexed with two
*
* If the above annotation is present on a type, it will be indexed with two
* stereotypes: {@code org.springframework.stereotype.Component} and
* {@code com.example.PrivilegedService}. While {@link Service} isn't directly
* annotated with {@code Indexed}, it is meta-annotated with {@link Component}.
* <p>
* It is also possible to index all implementations of a certain interface or
* all the sub-classes of a given class by adding {@code @Indexed} on it.
*
* <p>It is also possible to index all implementations of a certain interface or
* all the subclasses of a given class by adding {@code @Indexed} on it.
*
* Consider this base interface:
* <pre class="code">
* package com.example;
@ -64,6 +66,7 @@ import java.lang.annotation.Target; @@ -64,6 +66,7 @@ import java.lang.annotation.Target;
* &#064;Indexed
* public interface AdminService { ... }
* </pre>
*
* Now, consider an implementation of this {@code AdminService} somewhere:
* <pre class="code">
* package com.example.foo;
@ -72,13 +75,14 @@ import java.lang.annotation.Target; @@ -72,13 +75,14 @@ import java.lang.annotation.Target;
*
* public class ConfigurationAdminService implements AdminService { ... }
* </pre>
*
* Because this class implements an interface that is indexed, it will be
* automatically included with the {@code com.example.AdminService} stereotype.
* If there are more {@code @Indexed} interfaces and/or super classes in the
* If there are more {@code @Indexed} interfaces and/or superclasses in the
* hierarchy, the class will map to all their stereotypes.
*
* @author Stephane Nicoll
* @since 4.3.3
* @since 5.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

5
spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -38,6 +38,7 @@ public class CandidateComponentsIndexLoaderTests { @@ -38,6 +38,7 @@ public class CandidateComponentsIndexLoaderTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void validateIndexIsDisabledByDefault() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(null);
@ -101,7 +102,7 @@ public class CandidateComponentsIndexLoaderTests { @@ -101,7 +102,7 @@ public class CandidateComponentsIndexLoaderTests {
@Test
public void loadIndexWithException() throws IOException {
final IOException cause = new IOException("test exception");
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to load indexes");
this.thrown.expectCause(is(cause));
CandidateComponentsIndexLoader.loadIndex(new CandidateComponentsTestClassLoader(

Loading…
Cancel
Save