一、项目环境
最近学习Spring Cloud,在我使用的是教程是翟永超编写的《Spring Cloud 微服务实战》,之前没怎么学过Spring Boot的内容。
我本地使用的IDE是Eclipse4.8.0,安装了Maven插件。虽然《Spring Cloud 微服务实战》一书的代码都是使用基于Spring boot 1.x的,但我本人也自己亲自创建项目来调试,我自己创建的项目的SpringBoot是2.3.12.RELEASE版本的。
二、POM报错信息
当我创建完项目后,发现POM文件第一行有红叉,没有提示报错信息。在Problems窗口显示了报错信息,如下:
错误信息是:Unknown Maven Configuration Problem(这是最重要的信息了)
其他出错信息如下(从事后来看,以下信息并不重要):
Error occured processing 'com.luoch.springboot.study.starter.SpringBootFirstApplication'
org.springframework.core.annotation.AnnotationConfigurationException: Attribute 'proxyBeanMethods' in annotation [org.springframework.boot.SpringBootConfiguration] is declared as an @AliasFor nonexistent attribute 'proxyBeanMethods' in annotation [org.springframework.context.annotation.Configuration].; nested exception is java.lang.NoSuchMethodException: org.springframework.context.annotation.Configuration.proxyBeanMethods()
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.<init>(AnnotationUtils.java:2089)
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.from(AnnotationUtils.java:2056)
at org.springframework.core.annotation.AnnotationUtils.getAttributeAliasNames(AnnotationUtils.java:1726)
at org.springframework.core.annotation.AnnotationUtils.isSynthesizable(AnnotationUtils.java:1685)
at org.springframework.core.annotation.AnnotationUtils.synthesizeAnnotation(AnnotationUtils.java:1468)
at org.springframework.core.annotation.AnnotationUtils.synthesizeAnnotationArray(AnnotationUtils.java:1572)
at org.springframework.core.annotation.AnnotationUtils.getAnnotations(AnnotationUtils.java:231)
at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:76)
at org.springframework.asm.ClassReader.readAnnotationValues(ClassReader.java:2020)
at org.springframework.asm.ClassReader.accept(ClassReader.java:676)
at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
at org.springframework.ide.eclipse.core.java.classreading.JdtConnectedMetadataReader.<init>(JdtConnectedMetadataReader.java:45)
at org.springframework.ide.eclipse.core.java.classreading.JdtMetadataReaderFactory.getMetadataReader(JdtMetadataReaderFactory.java:53)
at org.springframework.ide.eclipse.core.java.classreading.CachingJdtMetadataReaderFactory.getMetadataReader(CachingJdtMetadataReaderFactory.java:38)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.registerBean(BeansJavaConfig.java:368)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig$2.call(BeansJavaConfig.java:229)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig$2.call(BeansJavaConfig.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: org.springframework.context.annotation.Configuration.proxyBeanMethods()
at java.lang.Class.getDeclaredMethod(Class.java:2130)
at org.springframework.core.annotation.AnnotationUtils$AliasDescriptor.<init>(AnnotationUtils.java:2082)
... 22 more
eclipse.buildId=4.8.0.I20180611-0500
java.version=1.8.0_202
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product -clean
这个问题梗住我很久,一直没有解决,虽然项目能正常编译、打包测试和运行,但是红叉就是很烦,关键是spring boot 2.x之前是没有这样的问题的,我很疑惑。
我把翟永超提供的项目代码(Spring Boot 1.x)导入到我的项目,发现它的没有报错。那是什么原因呢?
三、解决方法
百度了无数次,最后使用【Unknown pom.xml line 1 Maven Configuration Problem】这个关键字百度,终于找到了正确解决方法。
解决方法出自《解决pom文件报错 Unknown pom.xml /xuxian line 1 Maven Configuration Problem》这篇文章。
在pom文件中的<properties>节点中加入<maven-jar-plugin.version>3.0.0</maven-jar-plugin.version>然后右键项目进入Maven>Update Project...菜单点击
OK,问题得到解决。泪奔!!
四、是maven-jar-plugin版本问题?
这个暂时不追究,我猜是这样,我之前的SpringBoot没有学好,应该是springboot2.x的时候需要指定maven-jar-plugin的版本是3.0.0,而默认情况下,不是3.0.0。当然这仅仅是猜测。今天先到这里。之后再研究。