I went for a different solution (only possible with 3.2-SNAPSHOT since a new method is added to Hazelcast -> getOrCreateHazelcastInstance) some time ago.
public class HazelcastInstanceLoader {
private final static ILogger logger = Logger.getLogger(HazelcastInstanceLoader.class);
public static HazelcastInstance load(String instanceName) throws Exception {
String configName = System.getProperty("hazelcast.config");
if (configName == null) {
configName = "hazelcast.xml";
}
Config config;
if (configName.startsWith("file:")) {
String filename = configName.substring("file:".length());
logger.info("Using hazelcast configuration file: " + filename);
config = new FileSystemXmlConfig(filename);
} else {
logger.info("Using hazelcast classpath resource: " + configName);
config = new ClasspathXmlConfig(configName);
}
config.setInstanceName(instanceName);
return Hazelcast.getOrCreateHazelcastInstance(config);
}
}
And configured this in Spring like this:
<bean id="hazelcastInstance"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="com.hazelcast.webmonitor.HazelcastInstanceLoader.load"/>
<property name="arguments">
<list>
<value>default</value>
</list>
</property>
</bean>
And the web.xml is configured like this:
<filter>
<filter-name>hazelcast-filter</filter-name>
<filter-class>com.hazelcast.web.WebFilter</filter-class>
<init-param>
<param-name>instance-name</param-name>
<param-value>default</param-value>
</init-param>
</filter>