在使用cache.put()方法将值放入缓存时获取NullPointer异常。
环境: Jboss 7.2
这是我为重现此问题而编写的示例代码。
配置表单standalone.xml文件:
`<cache-container name="sampleCache" default-cache="default">
<local-cache name="default"/>
</cache-container>`
在部署描述符文件中添加了依赖性,例如
`<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.infinispan.commons" />
<module name="org.infinispan" />
</dependencies>
</deployment>
</jboss-deployment-structure>`
通过@Resource从Java代码获取缓存对象
`import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.infinispan.Cache;
/**
* InfiniSpanJbossCache Implementation
*
*/
@Startup
@Singleton
public class InfiniSpanJbossCacheExample {
@Resource(lookup="java:/jboss/infinispan/cache/sampleCache/default")
private static Cache<String, String> cache;
@PostConstruct
public static void deploy(){
cache.put("test","inserted1element");
}
}`
在尝试将一些值插入到cache(cache.put(“”,“”))时出现错误,我是否错过任何配置???