Spring Boot Geode 不满足的依赖性通过方法表达 'sessionRegion'

Spring Boot Geode Unsatisfied dependency expressed through method '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$$Lambda3/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$$Lambda3/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$$Lambda9/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$$Lambda9/0x00000008010306b8 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport are in unnamed module of loader 'app')

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

谢谢

更新 该应用程序 运行 与 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, then here and finally, here.

开始的依赖关系跟踪

作为 Version Compatibility Matrix for SBDG specifies, SBDG 1.2.13.RELEASE specifically includes, and is based on, SDG 2.2.12.RELEASE (already), which is (technically) based on 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' 
}

...

WARNING: SDG 2.2.12.RELEASE is officially based on Apache Geode 1.9.2, and though it should work reasonably well with Apache Geode 1.10, there could expectedly be limitations in certain use cases.

这与 Spring Initializer 没有什么不同,方便 generates。当然,Spring Initializer 现在使用 new SBDG BOM,这使得管理单个 SBDG 模块依赖性变得更加容易,这与Spring Boot 的 依赖管理管理传递依赖,包括第 3 方库。

关于异常...

在我看来,您确实遇到了 配置 问题,而不是 依赖关系 问题。

当然,很难确定,因为您共享的 Gradle 构建配置非常少,而且您的 [= 中没有代码片段159=] 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

此消息是指 SBDG 的 (Spring Java) configuration provided by SSDG and imported/auto-configured

未满足的依赖性”,或“参数 0”,是 sessionRegion(..) 中的第一个方法参数( Spring JavaConfig-based) @Bean定义方法在SSDG的configuration中声明。它依赖于创建“ClusteredSpringSessionsRegion.[=52= 所需的 GemFire 缓存实例(例如 ClientCache) ]

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

好吧,这就是框架接下来要尝试做的事情...解决缓存 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 provided

终于,我们找到了根本原因...

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

NOTE: ClientCacheConfiguration extends AbstractCacheConfiguration, which extends AbstractAnnotationConfigSupport, and therefore should have "access" to the protected hasValue(:Number) method.

主线程似乎在使用 AbstractAnnotationConfig.hasValue(:Number) 方法的 these Lambdas 之一中。

我不太确定这是什么意思...

org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration$$Lambda3/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)和缓存实例上的 same dependency

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$$Lambda9/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$$Lambda9/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$$Lambda9/0x00000008010306b8 
and org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport 

are in unnamed module of loader 'app')

我不熟悉这个错误消息(基本上,说 class(es) "are in unnamed module of loader 'app'.")什么?

Spring Boot 应用程序 运行 怎么样?

除了 Exception 消息外,肯定会提供示例应用程序、一项或多项测试、您的配置、日志、Stack Traces、设置,运行时间环境等,将继续努力理解这个问题的背景。

在这一点上,我真的想为您指出一个开始解决问题的方向。

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

很多问题是使用 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'