-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @PropertySources and ignoreResourceNotFound
Support repeatable @propertysource annotations in Java 8 and add @PropertySources container annotation for Java 6/7. Also add an ignoreResourceNotFound attribute to @propertysource allowing missing property resources to be silently ignored. This commit also introduces some generally useful methods to AnnotationUtils for working with @repeatable annotations. Issue: SPR-8371
- Loading branch information
Phillip Webb
committed
Oct 22, 2013
1 parent
8917821
commit e95bd9e
Showing
10 changed files
with
363 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2011 the original author or authors. | ||
* Copyright 2002-2013 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. | ||
|
@@ -18,6 +18,7 @@ | |
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
philwebb
Member
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
@@ -132,7 +133,9 @@ | |
* Javadoc for details. | ||
* | ||
* @author Chris Beams | ||
* @author Phillip Webb | ||
* @since 3.1 | ||
* @see PropertySources | ||
* @see Configuration | ||
* @see org.springframework.core.env.PropertySource | ||
* @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources() | ||
|
@@ -141,6 +144,7 @@ | |
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Repeatable(PropertySources.class) | ||
public @interface PropertySource { | ||
|
||
/** | ||
|
@@ -166,4 +170,13 @@ | |
*/ | ||
String[] value(); | ||
|
||
/** | ||
* Indicate if failure to find the a {@link #value() property resource} should be | ||
* ignored. | ||
* <p>{@code true} is appropriate if the properties file is completely optional. | ||
* Default is {@code false}. | ||
* @since 4.0 | ||
*/ | ||
boolean ignoreResourceNotFound() default false; | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
spring-context/src/main/java/org/springframework/context/annotation/PropertySources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2002-2013 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.annotation; | ||
|
||
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; | ||
|
||
/** | ||
* Container annotation that aggregates several {@link PropertySource} annotations. | ||
* | ||
* <p>Can be used natively, declaring several nested {@link PropertySource} annotations. | ||
* Can also be used in conjunction with Java 8's support for repeatable annotations, | ||
* where {@link PropertySource} can simply be declared several times on the same method, | ||
* implicitly generating this container annotation. | ||
* | ||
* @author Phillip Webb | ||
* @since 4.0 | ||
* @see PropertySource | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface PropertySources { | ||
|
||
PropertySource[] value(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@philwebb How is this supposed to work when using JDK < 8? java.lang.annotation.repetable seems to have @retention(RetentionPolicy.RUNTIME)... We just tried to run an example which uses @propertysource using JDK 1.7 and it fails with a ClassNotFoundException!