Spring Boot Geode Unsatisfied 通过方法'sessionRegion'表达的依赖

问题描述

我的 gradle.build 的正确依赖让我发疯!

为了访问 Apache Geode 1.10 服务器,我使用:

// Geode client dependency
implementation 'org.springframework.geode:spring-geode-starter:1.2.13.RELEASE'    
implementation 'org.springframework.data:spring-data-geode:2.2.12.RELEASE' 
implementation 'org.springframework.boot:spring-boot-starter-tomcat:2.2.13.RELEASE' 

失败并出现错误:

org.springframework.context.support.AbstractApplicationContext 596 refresh: 
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'ClusteredSpringSessions' defined in class path resource 
[org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.class]: 
Unsatisfied dependency expressed through method 'sessionRegion' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration': 
Initialization of bean failed; nested exception is java.lang.IllegalAccessError: 
class org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$703/0x0000000801025d10 
tried to access protected method 'boolean org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.hasValue(java.lang.Number)' 
(org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$703/0x0000000801025d10 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport are in unnamed module of loader 'app')

有什么可以告诉我 UnsatisfiedDependencyException'ClusteredSpringSessions' 缺少依赖项吗?

如果我删除 @EnableGemFireHttpSession 注释,则会出现错误

2021-02-02T19:29:49,011 WARN  [main] org.springframework.context.support.AbstractApplicationContext 596 refresh: 
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.class]:
Unsatisfied dependency expressed through method 'cacheManager' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration': 
Initialization of bean failed; nested exception is java.lang.IllegalAccessError: 
class org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$679/0x00000008010306b8 
tried to access protected method 'boolean org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.hasValue(java.lang.Number)'
(org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$679/0x00000008010306b8 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport are in unnamed module of loader 'app')

有什么可以告诉我 UnsatisfiedDependencyException'cacheManager' 缺少依赖项吗?

谢谢

UPDATE 该应用程序的运行方式类似于 Spring Boot @ComponentScan finds candidate component class but does not inject @Configuration beans,但更具体地

@SpringBootApplication
@ComponentScan({"api","rsocket","pricing","listeners","dealing","web"}) // scans packages for @ components
@EnableLogging(logLevel="debug",logFile="geodeApi.log")
public class Api {
    
    private static final Logger log = LogManager.getLogger(Api.class);

    public static void main(String[] args) {
        log.info("In Main");
        
        SpringApplication app = new SpringApplication(Api.class);
        app.setWebApplicationType(WebApplicationType.REACTIVE);
        SpringApplication.run(Api.class,args);
        
        log.info("Out Main");
    }
}

组件扫描查找各种@Component注释类,例如

@Component
@EnableClusterDefinedRegions(clientRegionShortcut=ClientRegionShortcut.PROXY)
public class ClientCache {
    
    private static final Logger log = LogManager.getLogger(ClientCache.class);
    
    @Resource
    private Region<String,String> admin;
    
    @Autowired
    LQuote lQuote;
    
    @Autowired
    LReject lReject;    
    
    @Autowired
    LDeal lDeal;
    
    @Autowired
    DealNumber dealNumber;
    
    @Autowired
    PriceService priceService;
    
    @PreDestroy
    public void onDestroy() throws Exception {
        
        log.info("onDestroy");
        
        String guid = UUID.randomUUID().toString().substring(0,8).toUpperCase();           
        admin.put(guid,"API Shutdown");
        
        // TODO: Cancel all open quote streams
        
        log.traceExit();
    }
    
    @Bean
    ApplicationRunner StartedUp(){      
        log.traceEntry("StartedUp");
            
        return args -> {            
        String guid = UUID.randomUUID().toString().substring(0,8).toUpperCase();       
        admin.put(guid,"API Started");
        
        lQuote.addListener();
        lReject.addListener();
        lDeal.addListener();
        
        // Get latest deal number
        int currentId = dealNumber.readCurrentId();
        
        // Set it + 1 in case the web server was reboot on the fly
        priceService.setCurrentId(currentId + 1);

        log.traceExit();
    };
}

解决方法

从技术上讲,没有必要显式声明 SDG 依赖项。

SBDG 依赖项(即 org.springframework.geode:spring-geode-starter)已包含 SDG (org.springframework.data:spring-data-geode)。您可以遵循从 here 开始,然后是 here,最后是 here 的依赖路径。

正如 SBDG 的 Version Compatibility Matrix 所指定的那样,SBDG 1.2.13.RELEASE 具体包括,并且是 based on,SDG 2.2.12.RELEASE(已经),即(技术上){{3} } Apache Geode 1.9.2

但是,如果您需要使用 Apache Geode 1.10,那么您可以(推荐)简单地声明依赖项管理以强制在您的 Gradle 构建中使用 Apache Geode 1.10

plugins {
  id 'org.springframework.boot' version '2.2.13.RELEASE'
  id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  id 'java'
}

dependencyManagement {
  dependencies {
    dependency 'org.apache.geode:geode-core:1.10.0'
    dependency 'org.apache.geode:geode-cq:1.10.0'
    dependency 'org.apache.geode:geode-lucene:1.10.0'
    dependency 'org.apache.geode:geode-wan:1.10.0'
  }
}

dependencies {
  implementation 'org.springframework.geode:spring-geode-starter:1.2.13.RELEASE`
  implementation 'org.springframework.boot:spring-boot-starter-tomcat' 
}

...

警告:SDG 2.2.12.RELEASE 正式基于 Apache Geode 1.9.2,虽然它应该与 Apache Geode 1.10 配合得很好,但在某些用例中可能会受到限制。

这与 Spring Initializer 对您来说很方便based on 没什么不同。当然,Spring Initializer 现在使用了 SBDG BOM,这使得管理单个 SBDG 模块依赖项变得更加容易,这与 Spring Boot 的 依赖项不同management 管理传递依赖项,包括第 3 方库。

关于例外...

在我看来,实际上您遇到的是配置问题,而不是依赖问题。

当然,鉴于您分享了非常少的 Gradle 构建配置并且没有来自您的 Spring Boot 应用程序配置的代码片段,仅提及和什么,这很难说我能够从 Exception 消息中获取。所以,现在,我将根据您提供的内容以及我所知道或可以得出的内容继续。

查看(第一)Exception 消息的这一部分:

Error creating bean with name 'ClusteredSpringSessions' defined in class path resource 
[org/springframework/session/data/gemfire/config/annotation/web/http/GemFireHttpSessionConfiguration.class]: 
Unsatisfied dependency expressed through method 'sessionRegion' parameter 0

而且,特别是:

Unsatisfied dependency expressed through method 'sessionRegion' parameter 0

此消息指的是 (Spring Java) generates 由 SSDG 提供,configuration 由 SBDG 提供。

未满足的依赖”或“参数 0”是 sessionRegion(..) (Spring JavaConfig) 中的第一个方法参数>-based) @Bean 定义方法在 SSDG 的 imported/auto-configured 中声明。它依赖于创建“ClusteredSpringSessionsClientCache 所需的 GemFire 缓存实例(例如 Region)。

那么现在问题变成了,缓存是如何创建的?

好吧,这就是框架接下来要尝试做的事情...解决缓存 bean 依赖项(实例引用),这需要首先触发缓存创建(由于依赖项顺序)...

Error creating bean with name 'org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration': 
Initialization of bean failed; nested exception is java.lang.IllegalAccessError

我们看到发生了 IllegalAccessError (O.o),这对我来说已经像是版本问题,但是...

ClientCacheConfiguration 是 SDG 的 configuration

最后,我们找到了根本原因......

class org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$703/0x0000000801025d10 
tried to access protected method 'boolean org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.hasValue(java.lang.Number)'

注意:ClientCacheConfiguration provided AbstractCacheConfiguration,其中 extends AbstractAnnotationConfigSupport,因此应该“访问”受保护的 hasValue(:Number) 方法。

主线程似乎位于使用 AbstractAnnotationConfig.hasValue(:Number) 方法的 extends 之一中。

我不完全确定这是什么意思...

org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$703/0x0000000801025d10 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport are in unnamed module of loader 'app'

您是否可能偶然使用 Spring Boot 的 新(分层)Docker 镜像支持?

实际上,第二个 Exception 消息(这次涉及 cacheManager bean)导致相同的结果。它没有什么不同,只是涉及另一个 bean(即 cacheManager bean)和缓存实例上的 these Lambdas

Error creating bean with name 'cacheManager' defined in class path resource 
[org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.class]
: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.data.gemfire.config.annotation.ClientCacheConfiguration': 
Initialization of bean failed; nested exception is java.lang.IllegalAccessError: 
class org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$679/0x00000008010306b8 
tried to access protected method 'boolean org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.hasValue(java.lang.Number)'
(org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$679/0x00000008010306b8 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport are in unnamed module of loader 'app')

而且,特别是:

Initialization of bean failed; nested exception is java.lang.IllegalAccessError: 

tried to access protected method 'boolean org.springframework.data.gemfire
 .config.annotation.support.AbstractAnnotationConfigSupport
    .hasValue(java.lang.Number)'

还有:

(org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda$679/0x00000008010306b8 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport 

are in unnamed module of loader 'app')

我不熟悉这个错误消息(基本上,说类“在加载器‘app’的未命名模块中。”)什么?

这个 Spring Boot 应用是如何运行的?

绝对提供示例应用程序、一个或多个测试、您的配置、日志、堆栈跟踪以及异常消息、设置、运行时环境等,将继续尝试了解这个问题的背景。

在这一点上,我真的想给你指明一个方向,开始解开这个问题。

抱歉,在这种情况下,我(目前)无法提供更多帮助。

,

很多问题是使用 Java JDK 15 版。 正确的版本需要 Java 11。

// Geode client dependency
implementation 'org.springframework.geode:spring-geode-starter:1.2.8.RELEASE'    
implementation 'org.springframework.data:spring-data-geode:2.2.8.RELEASE' 
implementation 'org.springframework.boot:spring-boot-starter-tomcat'

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...