Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeatable not found when using Spring 4 PropertySource

Tags:

java

spring

we are using Spring 4.0.1.RELEASE in combination with jdk6 (this is fixed). Of course we have done the config in Java with usage of the @PropertySource annotation. This leads to an annoying warning message(s) when we compile the project with gradle:

org\springframework\context\annotation\PropertySource.class(org\springframework\context\annotation:PropertySource.class): warning: Cannot find annotat ion method 'value()' in type 'java.lang.annotation.Repeatable': class file for java.lang.annotation.Repeatable not found

This is caused by the usage of not (in jdk6) existing Repeatable class and I am glad that it's just a warning. I love the clean output of gradle and this is just annoying because it may obfuscate other "real" warnings (like checkstyle...).

Maybe anyone faced the same problem and got a (not so much hack) solution for this situation. I just want to see a clean output again.

like image 722
meistermeier Avatar asked Feb 06 '14 08:02

meistermeier


People also ask

Is the @propertysource annotation repeatable?

The @PropertySource annotation is repeatable, according to Java 8 conventions. However, all such @PropertySource annotations need to be declared at the same level, either directly on the configuration class or as meta-annotations within the same custom annotation.

What is @propertysource annotation in Spring Boot?

Spring @PropertySource annotation is used to provide properties file to Spring Environment. This annotation is used with @Configuration classes. Spring PropertySource annotation is repeatable, means you can have multiple PropertySource on a Configuration class. This feature is available if you are using Java 8 or higher version.

What happens if property source is not found in spring?

If one or more specified PropertySource file is not found, spring will throw an Exception. 5. Ignore a Property file if not found Occasionally, you may want the app to ignore the property source not found exception. Spring throws an exception when a specified file is not found.

What happens if a property key is duplicated in spring?

If a property key is duplicated, the last declared file will ‘win’ and override. 4. Spring 4 and @PropertySources Some enhancements on Spring 4. 4.1 Introduces new @PropertySourcesto support Java 8 and better way to include multiple properties files.


1 Answers

I think that the problem is that in Spring 4, they use @Repeatable annotation, which has only been introduced in Java 8.

Therefore, if you're not using Java 8 you'll continue to see this problem, at least until this issue will be fixed.

BTW, this is also preventing the usage of @Scheduled annotation in older JDKs than Java 8. I hope it will be fixed soon.

like image 73
AlonL Avatar answered Oct 02 '22 06:10

AlonL