问题在于:
我有一个Dynamic Web Application
,我有一个sessions
列表作为静态字段,我现在正在研究将来可能出现的群集问题。
我想将静态HashMap
移动到可以独立于服务器访问的位置,换句话说,一旦我有2台服务器,并且静态HashMap
的服务器死亡,另一台服务器应该能够使用HashMap
缓存恢复infinispan
,因服务器故障不会丢失。
所以,我试过的是实现一些EmbededCacheManager
和一些CashContainers
,但是在大多数情况下,我遇到的问题是我根本无法将infinispan
jar添加到我的项目,并使用怪异的缓存。
我四处搜索,我找不到将依赖项添加到我的WEB项目的方法。网上的所有教程,例如这个:http://infinispan.org/docs/stable/getting_started/getting_started.html,都在使用Maven,但我没有。我需要一个Maven免费解决方案。
另外,我的代码:
static List<Session> sessions = new ArrayList<Session>();
我想做什么:
@Resource(lookup = "java:jboss/infinispan/container/myCache")
public CacheContainer myCache;
但我简直无法做对。 我在网上搜索过,发现我需要在MANIFEST.MF文件中为我的项目添加infinispan依赖项,一旦我这样做了:
Manifest-Version: 1.0
Dependencies: org.infinispan export
我将manifest
文件夹添加到src \ META-INF文件夹中(我也创建了该文件夹,因为它不存在),现在我可以导入infinispan.cache
但是,我无法构建我的整个项目,它总是在我的standalone.xml
文件中显示一些错误,就我添加的内容而言。
以下是代码:
<subsystem xmlns="urn:jboss:domain:infinispan:4.0">
<cache-container name="myCache" default-cache="default" module="org.wildfly.clustering.server">
<transport lock-timeout="60000"/>
<replicated-cache name="sessions" mode="SYNC">
</replicated-cache>
</cache-container>
...
<\subsystem>
在控制台中,WildFly 10顺便说一句,写的一行显示出问题的行和列,问题出在第二行和第四列(我不知道第四列在哪里,因为,在standalone.xml中,前几个字符是标签...?)
希望你有我的问题,因为,我不知道下一步该做什么。 谢谢。
答案 0 :(得分:1)
好的,我按照你的步骤进行了一些改动,
爪哇:
@Resource(lookup = "java:jboss/infinispan/container/myCache")
public CacheContainer myCache;
Standalone.xml
<replicated-cache name="sessions" mode="SYNC">
<transaction mode="BATCH"/> //added this line
</replicated-cache>
此外,在同一个standalone.xml
文件中,我收到了jgroup
子系统缺少依赖项的错误
<subsystem xmlns="urn:jboss:domain:jgroups:4.0">
对此的解决方案,我在standalone-full-ha.xml中找到了关于jgroups
所需的所有依赖关系,并将它们全部复制到standalone.xml
(我推荐Total Commander为此任务,他有内置工具来比较两个文件)
您的MANIFEST.MF
文件是正确的,他在src / META-INF文件夹中的位置也是正确的。
我曾经遇到类似问题infinispan
,所有问题都与Maven及其依赖关系有关,但是有一个解决方法。
你需要的是转到wildfly
文件夹,在那里你会找到文件夹module \ system \ layers \ base \ org \ infinispan \ main
在那里你会找到这个文件:infinispan-core-8.2.4.Final(也许是其他版本)
然后你必须去:
Wildfly \模块\ SYSTEM \层\基\有机\ Infinispan的\公地\主
在那里你会找到这个文件:infinispan-commons-8.2.4.Final(也许是其他版本)
这些文件是您wildfly
使用的文件(显然是:),并且它们具有您需要的infinispan
函数的正确版本。
将这两个文件复制到WEB / WebContent / WEB-INF / lib(我相信你有其他的jar)
如果还有其他infinispan
个jar,请删除它们,因为使用与服务器相同的版本非常重要。
完成后,您可以执行以下操作:
爪哇:
private List<Session> sessions() {
Cache<Integer, List<Session>> c = myCache.getCache("sessions");
// since you List is not a HashMap, you will need to make sure that
// you get this right
List<Session> l = c.get(1); // this returns the List, but with the key 1, read all the code, you will understand
if (l != null) { // if its ok, then return the list
return l;
} else { // you need to make sure the list exist in the cache, just for the first time, all the other times, l will be different then null
l = new ArrayList<Session>(); // make an empty list
c.put(1, l); //add it to the cache
return l; // use the list as you wish
}
}
这将允许您使用从缓存中直接获取的会话列表。
希望我能帮助你。否则,祝你好运,你需要它:)