spring java.lang.ClassNotFoundException: java.lang.annotation.Repeatable

spring4版本 spring boot 或者web应用或者其他方式启动时候,总是可以在启动时候看到如下错误,但又不影响使用,一直忽略,得空仔细看了一下

 

DEBUG AnnotationAttributesReadingVisitor - Failed to class-load type while reading annotation metadata. This is a non-fatal error, but certain annotation metadata may be unavailable.
java.lang.ClassNotFoundException: java.lang.annotation.Repeatable
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) ~[catalina.jar:7.0.59]
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ~[catalina.jar:7.0.59]
。。。。。
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) ~[catalina.jar:7.0.59]
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25]
	at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
	at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]

大概意思说有个注释有问题

 

java.lang.ClassNotFoundException: java.lang.annotation.Repeatable 是JAVA 8 注解特性,但我用的是JDK7

可能会有影响,写了简单代码,发现最终定位到是数据源加载配置文件的时候,内容如下

 

@Configuration
@PropertySource("conf/jdbc.properties")
public class ConfigDataSource extends BaseService{


@PropertySource 是spring 3.1开始提供的注释,说可以加载配置文件(key-value)到Environment 中,再通过Environment.getProperty(key) 来获取配置值

 

而@PropertySources 是spring 4.0开始提供的注释,注释解释如下

 

Container annotation that aggregates several PropertySource annotations.

Can be used natively, declaring several nested PropertySource annotations. Can also be used in conjunction with Java 8's support forrepeatable annotations, where PropertySource can simply be declared several times on the sametype, implicitly generating this container annotation.

大概意思可以提供多个PropertySource 组合,并支持Java8 的repeatable注释组合

 

想了一下,修改代码如下,解决问题

 

@Configuration
@PropertySources(value = {@PropertySource("classpath:conf/jdbc.properties")})

 

 

 

 

 

 

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值