【问题标题】:Redis Error in Spring Session sample using Maven and Spring Boot使用 Maven 和 Spring Boot 的 Spring Session 示例中的 Redis 错误
【发布时间】:2015-04-18 14:45:22
【问题描述】:

我尝试使用 Spring Boot + Maven 设置 this Spring-Session example(GIT 链接中的源代码使用 Gradle)。没有编译错误,可部署的 WAR 文件也是使用 repackage 目标生成的。

尝试在我的 WildFly 服务器中部署 WAR 文件时,我收到以下与 Redis 相关的错误。我的机器上没有运行 Redis 服务器(因为我假设嵌入式 Redis 实例将作为应用程序的一部分创建,即使在已部署的 WAR 文件中也是如此)

文件:EmbeddedRedisConfiguration.java

引起:

java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203) [rt.jar:1.8.0_25]
at java.nio.file.Files.copy(Files.java:2984) [rt.jar:1.8.0_25]
at redis.embedded.RedisServer.extractExecutableFromJar(RedisServer.java:85)
at redis.embedded.RedisServer.<init>(RedisServer.java:69)
at redis.embedded.RedisServer.<init>(RedisServer.java:63)
at hello.EmbeddedRedisConfiguration$RedisServerBean.afterPropertiesSet(EmbeddedRedisConfiguration.java:55)

环境:WildFly8.2 在域模式下运行(3 个节点在 Full-HA 配置文件中运行) 应用程序:Spring Boot + Spring Session + Maven

问题:这个错误是不是因为嵌入式 Redis 实例不能 在将 WAR 文件部署到容器时创建?我没有 尝试将其作为可执行 WAR 文件运行。

完整的错误堆栈

[Server:server-four] 23:52:46,815 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host."/gs-spring-boot-0.1.0": org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host."/gs-spring-boot-0.1.0": Failed to start service
[Server:server-four]    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
[Server:server-four]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
[Server:server-four]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
[Server:server-four]    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
[Server:server-four] Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisServer' defined in class path resource [hello/EmbeddedRedisConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
[Server:server-four]    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:222)
[Server:server-four]    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
[Server:server-four]    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
[Server:server-four]    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
[Server:server-four]    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
[Server:server-four]    ... 3 more
[Server:server-four] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisServer' defined in class path resource [hello/EmbeddedRedisConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException
[Server:server-four]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
[Server:server-four]    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
[Server:server-four]    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:116)
[Server:server-four]    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:611)
[Server:server-four]    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
[Server:server-four]    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
[Server:server-four]    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
[Server:server-four]    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
[Server:server-four]    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
[Server:server-four]    at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89)
[Server:server-four]    at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51)
[Server:server-four]    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
[Server:server-four]    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:182)
[Server:server-four]    ... 7 more
**[Server:server-four] Caused by: java.lang.NullPointerException
[Server:server-four]    at java.util.Objects.requireNonNull(Objects.java:203) [rt.jar:1.8.0_25]
[Server:server-four]    at java.nio.file.Files.copy(Files.java:2984) [rt.jar:1.8.0_25]
[Server:server-four]    at redis.embedded.RedisServer.extractExecutableFromJar(RedisServer.java:85)
[Server:server-four]    at redis.embedded.RedisServer.<init>(RedisServer.java:69)
[Server:server-four]    at redis.embedded.RedisServer.<init>(RedisServer.java:63)
[Server:server-four]    at hello.EmbeddedRedisConfiguration$RedisServerBean.afterPropertiesSet(EmbeddedRedisConfiguration.java:55)**
[Server:server-four]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613)
[Server:server-four]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550)
[Server:server-four]    ... 24 more
[Server:server-four] 

【问题讨论】:

    标签: maven redis wildfly spring-data-redis spring-session


    【解决方案1】:

    根据您的堆栈跟踪,嵌入式配置似乎无法在 WildFly 上运行。我创建了an issue 来解决它

    与此同时,您可以通过以下方式在 WildFly 上运行:

    • 删除EmbeddedRedisConfiguration
    • 确保启动外部 Redis 实例。您可以在Redis documentation 中找到安装 Redis 的说明

    注意:嵌入式 Redis 不适用于生产环境,只是为了让开发人员可以轻松地进行尝试。因此,这被视为一个相当小的问题。

    【讨论】:

    • 谢谢,我需要什么 maven/spring 配置才能让我的应用程序代码连接并保持它的 Spring Session 到这个外部 Redis 实例?任何端口号..等?在看到 Spring Session 示例附带的 Gradle 配置中的 reservePort() 定义后,我产生了这个疑问。
    • reservePort 是为了找到一个可用的端口,这样我就可以在 CI 服务器上运行(即我不知道 CI 服务器上有哪些端口是空闲的,所以它应该选择一个随机的可用端口)。
    • 所以,只要外部 Redis 实例启动并在与 WildFly 相同的机器上运行,代码就可以工作吗?我想知道我是否必须将 spring 代码或 WildFly 指向此 Redis 实例才能使此示例正常工作
    • 你可以指向任何你喜欢的端口和任何主机。您指向的示例当前正在使用 localhost 和默认的 Redis 端口(6379)。可以通过在 HttpSessionConfig 中指定 JedisConnectionFactory 上的连接信息来自定义查看github.com/spring-projects/spring-session/blob/1.0.0.RELEASE/…
    • @RobWinch 我认为这个问题与 WildFly 无关。因为我遇到了与试图在本地主机上运行的嵌入式 tomcat 完全相同的情况。我们迫切需要 Maven!正确!示例项目配置,因为我们浪费时间运行 gradle 示例。好主意,但这个项目有太多问题。
    【解决方案2】:

    这实际上是因为从maven中提取的embedded-redis-0.5.jarn与gradle不同,如果您可以设法将gradle中的embedded-redis-0.5.jar放入从maven构建的jar中,它将起作用.

    【讨论】:

      猜你喜欢
      • 2018-06-06
      • 2021-12-10
      • 2021-01-06
      • 1970-01-01
      • 2015-04-19
      • 2020-07-21
      • 2015-02-27
      • 2016-07-08
      • 2021-09-13
      相关资源
      最近更新 更多