【问题标题】:spring-data-geode and spring-boot-starter-webflux application run failedspring-data-geode 和 spring-boot-starter-webflux 应用程序运行失败
【发布时间】:2020-05-14 03:05:29
【问题描述】:

我有一个 webflux 项目,我正在添加 apache geode。在我的 build.gradle 我有:

implementation 'org.springframework.data:spring-data-geode:2.2.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-webflux:2.2.4.RELEASE'

添加 spring-data-geode 实现后,应用程序崩溃:

2020-01-28T16:29:51,965 INFO  [main] org.eclip.jetty.util.log.Log 169 initialized: Logging initialized @4337ms to org.eclipse.jetty.util.log.Slf4jLog
2020-01-28T16:29:52,050 WARN  [main] org.sprin.conte.suppo.AbstractApplicationContext 558 refresh: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletHolder
2020-01-28T16:29:52,064 INFO  [main] org.sprin.boot.autoc.loggi.ConditionEvaluationReportLoggingListener 136 logMessage: 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-01-28T16:29:52,072 ERROR [main] org.sprin.boot.SpringApplication 826 reportFailure: Application run failed
org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletHolder
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:81)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)

问题是,如果我添加

spring.main.web-application-type=nonespring.main.web-application-type=reactive 到我的 application.properties 然后会干扰 @ClientCacheApplication(name = "Web", locators = @Locator(host="1.2.3.4", port=10334), logLevel = "debug", subscriptionEnabled = true) 注释并且应用程序不会连接到 geode 定位器,也不会运行 @EnableClusterDefinedRegions 这会导致定义简单区域时出现问题,我想从服务器取货。

更新spring-boot-starter-web 添加到build.gradle 并使spring boot 应用程序类型为NONE 如下所示可以解决即时问题,但是...

SpringApplication app = new SpringApplication(Web.class);
app.setWebApplicationType(WebApplicationType.NONE);
SpringApplication.run(Web.class, args);

...但是 webflux 映射找不到 @Bean websocket 处理程序:

2020-01-28T16:54:26,236 DEBUG [http-nio-8082-exec-2] org.sprin.web.servl.handl.AbstractHandlerMapping 412 getHandler: Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2020-01-28T16:54:26,246 DEBUG [http-nio-8082-exec-2] org.sprin.web.servl.resou.ResourceHttpRequestHandler 454 handleRequest: Resource not found
2020-01-28T16:54:26,246 DEBUG [http-nio-8082-exec-2] org.sprin.web.servl.FrameworkServlet 1131 logResult: Completed 404 NOT_FOUND

这会导致网站出错:

控制台日志显示

WebSocket connection to 'ws://localhost:8082/ws/data' failed: Error during WebSocket handshake: Unexpected response code: 404

【问题讨论】:

    标签: spring-webflux spring-data-gemfire


    【解决方案1】:

    区域的问题是因为使用 @EnableClusterDefinedRegions 定义的区域的类 (a) 由 new 命令而不是 Spring @Autowired 实例化; (b) 在 Spring Boot @ComponentScan 看不到的另一个包中。一旦这些被修复,那么这些区域就会被自动定义并使用@Resource 注解进行处理。

    @Resource(name = "Example") private Region<Object, Object> example

    还给出了main 程序

    SpringApplication app = new SpringApplication(Web.class);
    app.setWebApplicationType(WebApplicationType.REACTIVE);
    SpringApplication.run(Web.class, args);
    

    通过在build.gradle 中获取正确的依赖关系,然后为 rSocket / webSocket 注释端点,解决了另一个问题:

    @MessageMapping(value = "helloWorld")
    public Flux<String> getFluxSocket() {
        log.traceEntry();
        log.info("In hello world");
    
        return Flux.just("{\"Hello\":\"World\"}");
    }
    

    @GetMapping(value = "/helloWorld", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> getRestSocket() {
        log.traceEntry();   
        return Flux.just("Hello World");
    }
    

    用于 HTTP 端点。

    【讨论】:

      猜你喜欢
      • 2019-10-28
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 2020-10-26
      • 2018-09-27
      • 2020-11-06
      • 2018-12-24
      相关资源
      最近更新 更多