我们有一个使用Spring MVC的应用程序。我们最近将构建过程更改为使用Maven 3.0.5而不是Maven 3.2.3(没有相关原因)并开始遇到部署到WebLogic中的异常。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.security.authentication.AuthenticationManager com.es3.ers.controller.AuthenticationController.authManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.es3.ers.filter.AuthenticationTokenProcessingFilter com.es3.ers.config.SecurityConfig.authenticationTokenProcessingFilter; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationTokenProcessingFilter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.springframework.security.authentication.AuthenticationManager com.es3.ers.filter.AuthenticationTokenProcessingFilter.authenticationManager; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'authenticationManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
一些研究在我们的代码中产生了一个问题,我们确实决定让应用程序再次运行,但它确实让我想到为什么Maven版本会以这种方式影响Spring。
我比较了3.0.5和3.2.3上构建的版本,而不是MANIFEST文件中的时间戳,没有差异。然后我查看了归档的结构,发现3.0.5版本有这三个(与bug有关)文件:
$ unzip -t ers.war | grep -E "(AuthenticationController|AuthenticationTokenProcessingFilter|SecurityConfig)\.class"
testing: WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class OK
testing: WEB-INF/classes/com/es3/ers/filter/AuthenticationTokenProcessingFilter.class OK
testing: WEB-INF/classes/com/es3/ers/config/SecurityConfig.class OK
3.2.3有三个相同的文件:
$ unzip -t ers.war | grep -E "(AuthenticationController|AuthenticationTokenProcessingFilter|SecurityConfig)\.class"
testing: WEB-INF/classes/com/es3/ers/filter/AuthenticationTokenProcessingFilter.class OK
testing: WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class OK
testing: WEB-INF/classes/com/es3/ers/config/SecurityConfig.class OK
您会注意到AuthenticationController在Maven 3.0.5和3.2.3中的AuthenticationTokenProcessingFilter之前,它们是相反的。出于想法,我从3.0.5档案中提取了文件,删除了它们并将它们添加回来,因此它们的顺序相同:
$ unzip ers.war WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class WEB-INF/classes/com/es3/ers/config/SecurityConfig.class
$ zip -d ers.war WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class WEB-INF/classes/com/es3/ers/config/SecurityConfig.class
$ zip -ru ers.war WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class WEB-INF/classes/com/es3/ers/config/SecurityConfig.class
$ unzip -t ers.war | grep -E "(AuthenticationController|AuthenticationTokenProcessingFilter|SecurityConfig)\.class"
testing: WEB-INF/classes/com/es3/ers/filter/AuthenticationTokenProcessingFilter.class OK
testing: WEB-INF/classes/com/es3/ers/controller/AuthenticationController.class OK
testing: WEB-INF/classes/com/es3/ers/config/SecurityConfig.class OK
在归档文件中的文件后,我们能够成功部署到WebLogic。修复显然是为了纠正我们代码中的错误,但这里发生了什么?我认为这与Maven相关,因为它显然以每个版本的一致顺序构建WAR,所以我觉得它改变了。 Maven 3.0.5和3.2.3使用相同版本的Maven WAR插件。