Java 使用 Spring 4 PropertySource 时找不到可重复的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21598016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Repeatable not found when using Spring 4 PropertySource
提问by meistermeier
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:
我们将 Spring 4.0.1.RELEASE 与 jdk6 结合使用(这是固定的)。当然,我们已经使用@PropertySource
注释在 Java 中完成了配置。当我们使用 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
org\springframework\context\annotation\PropertySource.class(org\springframework\context\annotation:PropertySource.class): 警告: 在类型 'java.lang.annotation.Repeatable' 中找不到注释方法 'value()': class找不到 java.lang.annotation.Repeatable 的文件
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...).
这是由于使用 not (在 jdk6 中)现有的可重复类引起的,我很高兴这只是一个警告。我喜欢 gradle 的干净输出,这很烦人,因为它可能会混淆其他“真实”警告(例如 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.
也许任何人都面临同样的问题,并针对这种情况获得了(不是很多黑客)解决方案。我只想再次看到干净的输出。
采纳答案by AlonL
I think that the problem is that in Spring 4, they use @Repeatable
annotation, which has only been introduced in Java 8.
我认为问题是在Spring 4 中,他们使用了@Repeatable
注解,而注解只在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.
因此,如果您不使用 Java 8,您将继续看到此问题,至少在此问题得到修复之前。
BTW, this is also preventing the usage of @Scheduled
annotation in older JDKs than Java 8. I hope it will be fixed soon.
顺便说一句,这也阻止了@Scheduled
在比 Java 8 更旧的 JDK 中使用注释。我希望它会很快得到修复。
回答by Jens Schauder
I guess if you just want to get rid of the warning you might be able to achieve this with a custom logger: http://www.gradle.org/docs/current/userguide/logging.html
我想如果您只是想摆脱警告,您可以使用自定义记录器来实现这一点:http: //www.gradle.org/docs/current/userguide/logging.html
I'd check the current implementation, and wrap it in something that filters out the warning you want to ignore, forwarding everything else unchanged.
我会检查当前的实现,并将其包装在过滤掉您想要忽略的警告的东西中,转发其他所有内容不变。
回答by scheffield
Just for the records: Use
仅供参考:使用
@PropertySources(@PropertySource("classpath:path/to/config"))
to get rid of the exception.
摆脱异常。
Credits goes to: http://www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.html
学分转到:http: //www.javacodegeeks.com/2013/11/how-to-using-propertysource-annotation-in-spring-4-with-java-7.html
回答by Bruno Carrier
A workaround to get rid of the warning below Java 8 is to use the following approach instead of the @Scheduled annotation:
摆脱 Java 8 下面警告的解决方法是使用以下方法而不是 @Scheduled 注释:
@PostConstruct
public void setupTaskScheduler() throws FileNotFoundException {
taskScheduler = new ConcurrentTaskScheduler();
taskScheduler.schedule(new Runnable(...), new CronTrigger("0 0 * * * *"));
}