整理生產環境與開發環境高頻報錯,涵蓋 Spring 版本衝突、JDK 不兼容、XML 命名空間缺失、類版本號不匹配四大類問題,附帶 Maven 依賴調整與配置修復方案。
Caused by: java.lang.reflect.MalformedParameterizedTypeException
Dubbo 2.x 默認依賴 spring-2.5.6.SEC03,專案引入 spring-3.2.x 或更高版本導致類簽名不匹配。
在 pom.xml 中排除 Dubbo 傳遞的 Spring 依賴:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
統一由專案直接依賴管理 Spring 版本。
Caused by: java.lang.IllegalStateException: Context namespace element 'annotation-config'
and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser]
are only available on JDK 1.5 and higher
Dubbo 依賴的 Spring 2.5 僅支援至 JDK 1.7,JDK 1.8 類版本號 52.0 導致解析器無法識別。
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found
for element 'dubbo:application'.
專案未引入 dubbo.jar,導致 Spring 無法加載 dubbo.xsd Schema。
添加 Dubbo 依賴(已按上文排除 Spring):
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions></exclusions>
</dependency>
編譯器 JDK 1.8,運行環境 JDK 1.7(如 Tomcat 7 默認 JRE)。
maven-compiler-plugin 指定 source/target 版本。mvn dependency:tree 定位傳遞衝突。<dependencyManagement> 統一管理核心框架版本。