简体   繁体   English

使用Spring 4 PropertySource时找不到可重复的内容

[英]Repeatable not found when using Spring 4 PropertySource

we are using Spring 4.0.1.RELEASE in combination with jdk6 (this is fixed). 我们将Spring 4.0.1.RELEASE与jdk6结合使用(这是固定的)。 Of course we have done the config in Java with usage of the @PropertySource annotation. 当然,我们使用@PropertySource注释在Java中完成了配置。 This leads to an annoying warning message(s) when we compile the project with gradle: 当我们使用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'中找不到annotat ion方法'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. 这是由于使用not(在jdk6中)现有的Repeatable类引起的,我很高兴它只是一个警告。 I love the clean output of gradle and this is just annoying because it may obfuscate other "real" warnings (like checkstyle...). 我喜欢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. 我只想再次看到干净的输出。

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. 顺便说一下,这也阻止了在旧版JDK中使用@Scheduled注释而不是Java 8.我希望它很快就能修复。

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

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. 我会检查当前的实现,并将其包含在过滤掉您要忽略的警告的内容中,并将其他所有内容保持不变。

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 * * * *"));    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM