首页 > 解决方案 > 在 Liberty 中运行时 Spring Boot 服务未自动装配,但在 TomCat 中运行良好

问题描述

我有一个在使用内置 Tomcat 运行时运行良好的 Spring Boot 应用程序。当我排除内置 Tomcat 实例并在 IBM Liberty 中部署时,大多数服务/控制器都可以正常工作。但是,我的 2 个服务无法自动装配,在调用它们时收到 NPE。

我看到的日志是:

实际错误

Caused by: java.lang.NullPointerException
        at com.services.adminsuite.features.linkedattributes.controllers.LinkedAttributesController.getAllConfigurations(LinkedAttributesController.java:122)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
        at java.lang.reflect.Method.invoke(Method.java:508)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)

启动差异

[AUDIT   ] CWWKG0102I: Found conflicting settings for defaultKeyStore instance of keyStore configuration.
  Property password has conflicting values:
    Secure value is set in file:/opt/IBM/JazzTeamServer702-app10/wlp/usr/servers/pxs/GeneratedSSLInclude.xml.
    Secure value is set in file:/opt/IBM/JazzTeamServer702-app10/wlp/usr/servers/pxs/server.xml.
  Property password will be set to the value defined in file:/opt/IBM/JazzTeamServer702-app10/wlp/usr/servers/pxs/server.xml.

[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications.
[WARNING ] CWWKT0023W: The configured defaultHostName pxsjts could not be resolved, using localhost instead.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/ibm/adminCenter/serverConfig-1.0/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/adminCenter/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/ibm/adminCenter/explore-1.0/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/IBMJMXConnectorREST/
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/ibm/api/
[WARNING ] CWNEN0047W: Resource annotations on the fields of the org.springframework.web.servlet.view.tiles3.TilesConfigurer$CompositeELResolverImpl class will be ignored. The annotations could not be obtained because of the exception : java.lang.NoClassDefFoundError: org.apache.tiles.el.ScopeELResolver
[WARNING ] CWNEN0049W: Resource annotations on the methods of the org.springframework.web.servlet.view.tiles3.TilesConfigurer$CompositeELResolverImpl class will be ignored. The annotations could not be obtained because of the exception : java.lang.NoClassDefFoundError: org.apache.tiles.el.ScopeELResolver
21:18:13.805 [Default Executor-thread-3] INFO org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension - Activating CDI extension for Spring Data JPA repositories.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9081/pxs/
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)
2021-07-13 21:18:15.656  INFO 123564 --- [ecutor-thread-4] c.p.services.adminsuite.WebInitializer   : Starting WebInitializer on  with PID 123564 (/opt/IBM/JazzTeamServer702-app10/wlp/usr/servers/pxs/apps/expanded/pxs.war/WEB-INF/classes started by in /opt/IBM/JazzTeamServer702-app10/wlp/usr/servers/pxs)
2021-07-13 21:18:15.657  INFO 123564 --- [ecutor-thread-4] c.p.services.adminsuite.WebInitializer   : The following profiles are active: prod
2021-07-13 21:18:16.755  INFO 123564 --- [ecutor-thread-4] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2021-07-13 21:18:16.906  INFO 123564 --- [ecutor-thread-4] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 144ms. Found 13 repository interfaces.
2021-07-13 21:18:17.424  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c4bbc7fd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.460  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$5d699037] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.466  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.469  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@f8b13266' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.472  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityConfiguration' of type [com.services.adminsuite.core.config.MethodSecurityConfiguration$$EnhancerBySpringCGLIB$$e74ada7b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.481  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.Jsr250MetadataSourceConfiguration' of type [org.springframework.security.config.annotation.method.configuration.Jsr250MetadataSourceConfiguration$$EnhancerBySpringCGLIB$$a7934aff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.484  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'jsr250MethodSecurityMetadataSource' of type [org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.485  INFO 123564 --- [ecutor-thread-4] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-13 21:18:17.511  INFO 123564 --- [ecutor-thread-4] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1832 ms

org.apache.tiles.el.ScopeELResolver NoClassDefFound 错误我在使用 Liberty 时在其他日志中的其他地方看到过,因此似乎不相关但不确定。虽然 BeanPostProcessor 很有趣,但也不确定是否存在(注释掉了类上的方法安全性,但它仍在发生)。

你知道为什么 Liberty 处理这些和 Tomcat 的方式会有什么不同吗?或者调试这个的任何提示?

谢谢你,马特

标签: springspring-bootspring-mvcwebsphere-liberty

解决方案


结果是有问题的控制器端点(其中 3 个),由于某种原因缺少访问修饰符。在方法中添加保护解决了这个问题。这在 Tomcat 中不是问题,但只有在 Liberty 上运行时才会出现。再次感谢您的帮助(并为发布后不久休假而迟到的回复道歉)


推荐阅读