最近做了一次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