parent
c42d44a42c
commit
d96738d613
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -24,21 +24,21 @@ import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicate that the annotated element represents a stereotype for the index.
|
* 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
|
* scanning that uses a metadata file generated at compilation time. The
|
||||||
* index allows retrieving the candidate components (i.e. fully qualified
|
* index allows retrieving the candidate components (i.e. fully qualified
|
||||||
* name) based on a stereotype. This annotation instructs the generator to
|
* name) based on a stereotype. This annotation instructs the generator to
|
||||||
* index the element on which the annotated element is present or if it
|
* index the element on which the annotated element is present or if it
|
||||||
* implements or extends from the annotated element. The stereotype is the
|
* implements or extends from the annotated element. The stereotype is the
|
||||||
* fully qualified name of the annotated element.
|
* 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},
|
* with this annotation. If a component is annotated with {@link Component},
|
||||||
* an entry for that component will be added to the index using the
|
* an entry for that component will be added to the index using the
|
||||||
* {@code org.springframework.stereotype.Component} stereotype.
|
* {@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:
|
* custom annotation:
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* package com.example;
|
* package com.example;
|
||||||
|
|
@ -50,13 +50,15 @@ import java.lang.annotation.Target;
|
||||||
* @Service
|
* @Service
|
||||||
* public @interface PrivilegedService { ... }
|
* public @interface PrivilegedService { ... }
|
||||||
* </pre>
|
* </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
|
* stereotypes: {@code org.springframework.stereotype.Component} and
|
||||||
* {@code com.example.PrivilegedService}. While {@link Service} isn't directly
|
* {@code com.example.PrivilegedService}. While {@link Service} isn't directly
|
||||||
* annotated with {@code Indexed}, it is meta-annotated with {@link Component}.
|
* 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
|
* <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.
|
* all the subclasses of a given class by adding {@code @Indexed} on it.
|
||||||
|
*
|
||||||
* Consider this base interface:
|
* Consider this base interface:
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* package com.example;
|
* package com.example;
|
||||||
|
|
@ -64,6 +66,7 @@ import java.lang.annotation.Target;
|
||||||
* @Indexed
|
* @Indexed
|
||||||
* public interface AdminService { ... }
|
* public interface AdminService { ... }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Now, consider an implementation of this {@code AdminService} somewhere:
|
* Now, consider an implementation of this {@code AdminService} somewhere:
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* package com.example.foo;
|
* package com.example.foo;
|
||||||
|
|
@ -72,13 +75,14 @@ import java.lang.annotation.Target;
|
||||||
*
|
*
|
||||||
* public class ConfigurationAdminService implements AdminService { ... }
|
* public class ConfigurationAdminService implements AdminService { ... }
|
||||||
* </pre>
|
* </pre>
|
||||||
|
*
|
||||||
* Because this class implements an interface that is indexed, it will be
|
* Because this class implements an interface that is indexed, it will be
|
||||||
* automatically included with the {@code com.example.AdminService} stereotype.
|
* 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.
|
* hierarchy, the class will map to all their stereotypes.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 4.3.3
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -38,6 +38,7 @@ public class CandidateComponentsIndexLoaderTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateIndexIsDisabledByDefault() {
|
public void validateIndexIsDisabledByDefault() {
|
||||||
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(null);
|
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(null);
|
||||||
|
|
@ -101,7 +102,7 @@ public class CandidateComponentsIndexLoaderTests {
|
||||||
@Test
|
@Test
|
||||||
public void loadIndexWithException() throws IOException {
|
public void loadIndexWithException() throws IOException {
|
||||||
final IOException cause = new IOException("test exception");
|
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.expectMessage("Unable to load indexes");
|
||||||
this.thrown.expectCause(is(cause));
|
this.thrown.expectCause(is(cause));
|
||||||
CandidateComponentsIndexLoader.loadIndex(new CandidateComponentsTestClassLoader(
|
CandidateComponentsIndexLoader.loadIndex(new CandidateComponentsTestClassLoader(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue