最近做了一次spring版本的升级从3升级到4.

突然报出java.lang.ClassNotFoundException: java.lang.annotation.Repeatable的错误

 

通过google找到如下解决方法:

java.lang.annotation.Repeatable annotation that is the meta annotation used to mark your annotations for multiple usage in Java 8 (but I am using Java 7 in the project). 

这个问题产生于 要spring4 的 @PropertySource 注释中。

首先repeatable这个是java8里面的用法,它在spring4的工具类中有用到,但是如果我用的是jdk7并使用spring4怎么办呢?

 

一般情况下当我们调用@PropertySource时,是这样的:

@PropertySource("classpath:/datasource.properties")

 

但在spring4中为了避免Repeatable错误,我们可以这样使用,这样可以解决java版本兼容性的问题:

@PropertySources(value = {@PropertySource("classpath:/datasource.properties")})

 

有关这个问题的描述可以看这里: https://jira.springsource.org/browse/SPR-11086

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐