我试图设置自由配置文件服务器,以便缓存POJO。我的问题是如何在java代码中访问DistributedMap?
我的server.xml:
<featureManager>
<feature>jsp-2.2</feature>
<feature>jaxrs-1.1</feature>
<feature>localConnector-1.0</feature>
<feature>appSecurity-2.0</feature>
<feature>jpa-2.0</feature>
<feature>jdbc-4.0</feature>
<feature>jndi-1.0</feature>
<feature>cdi-1.0</feature>
<feature>webCache-1.0</feature>
<feature>distributedMap-1.0</feature>
</featureManager>
<distributedMap id="baseCache" libraryRef="TSPlib" memorySizeInMB="500" jndiName="services/cache/baseCache">
<diskCache></diskCache>
</distributedMap>
<library id="TSPlib">
<folder dir="C:\TSP\bin"></folder>
</library>我尝试了下面的代码(诚然,这是WAS的代码),但是我找不到DistributedMap的正确命名空间,也找不到它所在的jar。
公共类CachingService {
private DistributedMap cache = null;
public CachingService() {
InitialContext ctx;
try {
ctx = new InitialContext();
cache = (DistributedMap) ctx.lookup("services/cache/baseCache");
} catch (NamingException e) {
e.printStackTrace();
}
}发布于 2015-01-07 16:06:20
看起来像是一个错误,就像在distributedMap配置中提供的jndiName="services/cache/baseCache"和在查找中使用的:ctx.lookup("services/cache/TestCache")
如果不提供自定义jndiName,则默认services/cache/distributedmap。请参阅distributedMap-1.0
https://stackoverflow.com/questions/27818492
复制相似问题