Spring,Infinispan和JBoss 7集成 [英] Spring, Infinispan and JBoss 7 integration
问题描述
我正在尝试将JBoss 7 Infinispan缓存用作两个基于战争的基于Spring的应用程序的通信形式(稍后再介绍).我在访问JBoss托管的缓存管理器时遇到问题.
I'm trying to use JBoss 7 Infinispan cache as a communication form (something more later) of two war-deployed spring-based apps. I'm having a problem with accessing the JBoss managed cache managers.
当我使用
DefaultCacheManager cacheManager = new DefaultCacheManager();
cache = cacheManager.getCache();
在两个应用程序中的每个应用程序上,我都有两个单独的缓存.有没有办法完全不使用@ManagedBean批注和Java EE标准来访问JBoss服务器创建的缓存?
on each of two applications, I get two separate caches. Is there any way to access the cache created by JBoss server without using the @ManagedBean annotation and Java EE standard at all ?
完成了.感谢Kazaag,我使用了JNDI.
It's done. Thanks to Kazaag, I used JNDI.
JndiTemplate jndiTemplate = new JndiTemplate();
jndiTemplate.lookup("java:jboss/infinispan/container/cluster");
我对DefaultEmbeddedCacheManager Class Cast Exception有一个众所周知的问题.我用了反射.
I had the well known problem with a DefaultEmbeddedCacheManager Class Cast Exception. I used reflections.
Map<Object, Object> cache;
JndiTemplate jndiTemplate = new JndiTemplate();
Object cacheManager;
try {
cacheManager = (Object) jndiTemplate.lookup("java:jboss/infinispan/container/cluster");
Method method = cacheManager.getClass().getMethod("getCache");
cache = (Map) method.invoke(cacheManager);
} catch (Exception e) {
e.printStackTrace();
return;
}
此外,我必须将容器标记为急切开始.
Moreover I had to mark container as started eagerly.
<cache-container name="cluster" aliases="ha-partition" default-cache="default">
<transport lock-timeout="60000"/>
<replicated-cache name="default" mode="SYNC" start="EAGER" batching="true">
<locking isolation="REPEATABLE_READ"/>
</replicated-cache>
</cache-container>
尽管不同的类加载器也可以复制缓存.
The cache is replicated although different class loaders.
推荐答案
如果每个应用程序都使用自己的缓存管理器,则它们将被分开缓存.
If each application are using there own cache manager, they will have separated cached.
您可以通过Spring的JNDI支持来检索由应用程序服务器管理的缓存容器(JNDI名称为java:jboss/infinispan/my-container-name
).因此,Spring将负责确保每个部件都使用相同的容器.
You can retrieve the cache container managed by the application server via JNDI support of Spring (The JNDI name is java:jboss/infinispan/my-container-name
). So Spring will be responsible to make sure every part are using the same container.
我不是100%肯定会获得相同的缓存,它可能会返回给您特定于应用程序的缓存(这两个应用程序数据对象实际上来自不同的类加载器).
I am not 100% sure you will get the same cache, it may return you a application specific cache (the 2 applications data object are in fact coming from different class loader).
嵌入式缓存可能并不意味着应用程序间进行通信.您可能需要使用客户端/服务器范例.
Embedded cache is probably not mean for inter application communication. You probably need to use the client/server paradigm.
这篇关于Spring,Infinispan和JBoss 7集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!