即使输入的值不为null,infinispan cache.put()也会引发null指针异常 [英] infinispan cache.put() throws null pointer exception even when values put are not null

查看:76
本文介绍了即使输入的值不为null,infinispan cache.put()也会引发null指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图将内容添加到infinispan缓存中,当我使用put方法时,出现空指针异常.我的是一个JSF Web应用程序.我们正在尝试使用wildfly 13实现会话复制.

trying to add content to infinispan cache and I get null pointer exception when i use the put method. Mine is a JSF web application. We are trying to achieve session replication using wildfly 13.

import org.infinispan.Cache;
public class index extends AbstractPageBean implements java.io.Serializable {
    @Resource(lookup = "java:jboss/infinispan/cache/web/web_repl")  
    Cache<String, String> ilsCache;  
    public Cache<String, String> getCache() {
        return ilsCache;
    }

    public void prerender() {
        ilsCache.put("Message", "Hello");
        logger.info("CACHE " + getCache());
    }

日志文件

2018-08-21 14:21:57,134 ERROR [biz.autoscan.ils.index] (default task-1) index.java::Exception occured  : java.lang.NullPointerException
    at biz.autoscan.ils.index.btnLogin_action(index.java:930)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
    at java.lang.Thread.run(Thread.java:745)

有什么主意,为什么我仍然从cache.put()获得空指针异常?

Any idea why I still get null pointer exception fro cache.put()?

我们在域模式下使用WildFly 13,在复制模式下使用Infinispan.我的目标是将会话对象存储在infinispan缓存中,并在所有节点之间共享它.

We are using WildFly 13 in domain mode and Infinispan in replication mode. My aim is to store the session object in the infinispan cache and share it between all the nodes.

domain.xml中的Infinispan子系统:这就是我配置infinispan的方式.目前我们仅使用两台服务器,因此我们采用了复制模式.

Infinispan subsystem in domain.xml: This is how I have configured infinispan. We are using only two servers at the moment hence we have gone with replication mode.

<subsystem xmlns="urn:jboss:domain:infinispan:6.0">
    <cache-container name="web" aliases="ilsee" default-cache="web_repl" module="org.wildfly.clustering.web.infinispan">
        <transport channel="ee" lock-timeout="60000"/>
        <local-cache name="Username"/>
        <replicated-cache name="web_repl">
            <transaction mode="BATCH"/>
        </replicated-cache>
        <distributed-cache name="dist">
            <transaction mode="NON_XA"/>
            <file-store/>
        </distributed-cache>
    </cache-container>
</subsystem>

推荐答案

答案取决于您如何配置服务器.

The answer depends on how you configure your server.

我将提供一个通用示例.首先,您需要配置standalone.xml文件

I will provide a generic example. First, you need to configure your standalone.xml file

<subsystem xmlns="urn:infinispan:server:core:9.2">
 <cache-container module="org.infinispan.extension:ispn-9.2" name="infinispan_container" default-cache="default">
   <transport/>
   <global-state/>
   <distributed-cache name="default"/>
   <distributed-cache name="myCache"/>
 </cache-container>
</subsystem>

然后在Java应用程序中,您需要使用注入资源

Then in your Java application, you need to inject the resource using

@Resource(lookup = "java:jboss/datagrid-infinispan/container/infinispan_container/cache/myCache")
Cache cache;

您会看到 infinispan_container myCache 是您在XML配置文件中提供的值.

As you can see infinispan_container and myCache are values that you provided in the XML configuration file.

在Wildfly中,应用程序可以使用两种可能的方式来利用Infinispan:嵌入式模式和服务器模式.您可以找到更多信息 http://infinispan.org/docs/stable/user_guide/user_guide.html#usage_3

There are two possible ways for your application to utilize Infinispan within Wildfly: embedded mode and server mode. You can find more information http://infinispan.org/docs/stable/user_guide/user_guide.html#usage_3

这篇关于即使输入的值不为null,infinispan cache.put()也会引发null指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆