Spring 在 Liberty 中 运行 时引导服务未自动连接,但在 TomCat 中工作正常

Spring Boot Service not Autowired when running in Liberty, but works fine in TomCat

我有一个 Spring 启动应用程序,它在 运行 内置 Tomcat 时运行良好。当我排除内置 Tomcat 实例并在 IBM Liberty 中部署时,大多数 services/controllers 工作正常。但是,我的 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$d699037] 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 的虽然很有趣,但也不确定(在 class 上注释掉方法安全性,但它仍在发生)。

您知道为什么 Liberty 处理这些内容的方式与 Tomcat 有什么不同吗?或者有什么调试技巧吗?

谢谢, 马特

原来控制器端点有问题(其中 3 个),由于某种原因缺少访问修饰符。将 protected 添加到方法中可以解决问题。这在 Tomcat 中不是问题,但仅当在 Liberty 上 运行 时才存在。再次感谢您的帮助(并为发布后不久就去度假而迟到的回复表示歉意)