Hazelcast和Spring Session:REST API返回epmty值

时间:2016-06-03 09:35:36

标签: hazelcast spring-session

我尝试整合Spring Session和Hazelcast。我使用非常简单的配置:

 com.hazelcast.config.Config cfg = new com.hazelcast.config.Config();
    NetworkConfig netConfig = new NetworkConfig();
    netConfig.setPort(SocketUtils.findAvailableTcpPort());
    System.out.println("Hazelcast port #: " + netConfig.getPort());
    cfg.setNetworkConfig(netConfig);
    SerializerConfig serializer = new SerializerConfig().setTypeClass(Object.class)
            .setImplementation(new ObjectStreamSerializer());
    cfg.getSerializationConfig().addSerializerConfig(serializer);
    return Hazelcast.newHazelcastInstance(cfg);

这是来自Spring docs的例子。一切都还好,但是当我尝试使用其Rest APi从Hazelcast获取会话时,它返回空值0curl: (52) Empty reply from server

$ curl -X GET http://localhost:port/hazelcast/rest/maps/spring:session:sessions/session-id

port为端口,SocketUtils.findAvailableTcpPort()session-id选择的是浏览器中的会话ID。

如何使用Hazelcast REST API访问我保存的会话?

更新

通过添加cfg.setProperty("hazelcast.rest.enabled","true");,所有问题都消失了。

1 个答案:

答案 0 :(得分:1)

您必须激活默认禁用的REST API服务(出于安全原因)。请参阅http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#system-properties并搜索hazelcast.rest.enabled