java - Maven 版本影响 Spring MVC 部署
问题描述
我们有一个使用 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 中的 AuthenticationTokenProcessingFilter 之前,而在 3.2.3 中它们是相反的。出于想法,我从 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 插件。
解决方案
推荐阅读
- javascript - 我可以在 JSON Stringify 请求中使用 JS 变量作为节点吗?
- c# - 示例应用程序的 Ignite Compute 应用程序结果不正确 - 检查示例
- java - Android:RecyclerView.SetAdapter 导致应用程序崩溃,但没有明显错误
- python - 单击停止按钮后Python中的错误
- amazon-web-services - 使用 ElasticSearch 的 AWS DynamoDB 地理空间查询
- javascript - 弹出firebase通知时应用程序出现故障
- javascript - 如何仅使用 npm 或 yarn 安装项目的对等依赖项?
- amazon-cloudformation - 从名称中获取 TargetGroupArn?
- node.js - Backtest.js“ReferenceError:未定义列表”
- node.js - 在 Node.js 中,使用 async / await 处理错误的正确方法是什么?