繁体   English   中英

从Spring 4.3.2升级到5.0.2导致缺少@AliasFor错误

[英]Upgrade from spring 4.3.2 to 5.0.2 is causing missing @AliasFor error

当我尝试将Spring Web-MVC应用程序从4.3.2版本升级到5.0.2时,我在servlet xml中遇到错误。 错误发生在下一行,

<context:component-scan base-package="com.mypackage" />

错误如下

处理注解[org.springframework.stereotype.Controller]中的属性[value]的XML'@AliasFor声明丢失必需的'attribute'值时发生错误。 有关更多详细信息,请参见错误日志。

这就是我的servlet xml的样子。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd">


<security:global-method-security secured-annotations="enabled"/>

<context:component-scan base-package="com.mypackage" />

<mvc:view-controller path="/" view-name="index"/>

<mvc:resources mapping="/resources/**" location="/resources/" />

</beans>

如果我使用5.0.0,则不会发生此错误。 由于抱怨org.springframework.stereotype.Controller中缺少注释,我试图找出Controller中新添加或缺失的内容。 我可以看到在5.0.2版中添加了新行,并且缺少“属性”。

@AliasFor(annotation = Component.class)

我确信我的bean类定义中缺少某些内容,这是版本5.0.2所必需的。

我要检查三件事。

首先,您需要确保依赖关系管理正确。 您可以运行mvn dependency:tree并检查所有Spring依赖项是否使用相同的版本。 如果将来希望避免此类问题,可以使用Spring Framework BOM,并让其管理Spring Framework工件的版本:

<dependencyManagement>
    <dependencies>
            <dependency> 
                <groupId>org.springframework</groupId> 
                <artifactId>spring-framework-bom</artifactId> 
                <version>${spring.version}</version> 
                <type>pom</type> 
                <scope>import</scope> 
            </dependency> 
        </dependencies> 
</dependencyManagement>

如果依赖性管理正确,则可能是JAR损坏。 您可以清除内容并使用mvn dependency:purge-local-repository重新下载依赖项。

最后,不再建议在XML中使用版本化架构-实际上,从Spring Framework 5.0开始,不再支持该版本,请参阅SPR-13499

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM