복붙노트

[SPRING] Hazelcast를 스프링을 사용하는 세션 캐싱에 대해 노드 집합으로 제한하면서 구성하는 방법은 무엇입니까?

SPRING

Hazelcast를 스프링을 사용하는 세션 캐싱에 대해 노드 집합으로 제한하면서 구성하는 방법은 무엇입니까?

Spring을 사용하여 Hazelcast 세션 캐싱을 설정해야합니다. hazelcast 문서의 구성을 사용하는 것은 간단합니다. 그러나, 그것의 부족합니다. 내 환경 (DEV, QA, PROD) 각각에 대해 다른 구성 파일을 사용해야합니다. 대안 적으로 (이상적으로) 스프링 컨테이너의 초기화 중에 설정되는 스프링 빈의 여러 속성을 사용하고 싶습니다. hazelcast 설명서에 따르면, 내가해야 할 일은 각각의 환경에 맞는 그룹을 설정하는 것입니다. 이렇게 :

<hazelcast>
    <group>
       <name>dev</name>
       <password>dev-pass</password>
   </group>
   ...
</hazelcast>

보너스로, 캐시를 세션 및 응용 프로그램 수준 개체 (지도, 대기열 등)에 사용되는 단일 캐시로하고 싶습니다.

아무도 그들이 이것을 어떻게 할 것인지 예를 공유 할 수 있습니까? 도와 줘서 고마워.

해결법

  1. ==============================

    1.제안 된 답변에 감사드립니다. 그러나, 나는 다음과 같은 구성을 사용하여 이것을 해결했다고 생각한다. 이 구성에 대해 아무에게도 의견을 보내 주시면 감사하겠습니다.

    제안 된 답변에 감사드립니다. 그러나, 나는 다음과 같은 구성을 사용하여 이것을 해결했다고 생각한다. 이 구성에 대해 아무에게도 의견을 보내 주시면 감사하겠습니다.

    내 접근 방식 :

    1) 스프링 구성으로 인스턴스를 설정합니다. 2) 웹 필터 구성을 사용하여 최소한으로 구성된 hazelcast.xml 파일을 사용하여 인스턴스를 향상시킵니다. mulitcast 및 tcp-ip joiners는 false입니다.

    веб.хмл :

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/servlet-context.xml,
                /WEB-INF/spring/root-context.xml,
                ....
                /WEB-INF/spring/hazelcastContext.xml
            </param-value>
        </context-param>
    
    
    <listener>
    
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
    </listener>
    ....
    
    <filter>
        <filter-name>hazelcast-filter</filter-name>
        <filter-class>com.hazelcast.web.WebFilter</filter-class>
        <!--
            Name of the distributed map storing
            your web session objects
        -->
        <init-param>
            <param-name>map-name</param-name>
            <param-value>my-sessions</param-value>
        </init-param>
        <!--
            How is your load-balancer configured?
            stick-session means all requests of a session
            is routed to the node where the session is first created.
            This is excellent for performance.
            If sticky-session is set to false, when a session is updated
            on a node, entry for this session on all other nodes is invalidated.
            You have to know how your load-balancer is configured before
            setting this parameter. Default is true.
        -->
        <init-param>
            <param-name>sticky-session</param-name>
            <param-value>true</param-value>
        </init-param>
        <!--
            Name of session id cookie
        -->
        <init-param>
            <param-name>cookie-name</param-name>
            <param-value>hazelcast.sessionId</param-value>
        </init-param>
        <!--
            Domain of session id cookie. Default is based on incoming request.
        -->
        <init-param>
            <param-name>cookie-domain</param-name>
            <param-value>.mycompany.com</param-value>
        </init-param>
        <!--
            Should cookie only be sent using a secure protocol? Default is false.
        -->
        <init-param>
            <param-name>cookie-secure</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Should HttpOnly attribute be set on cookie ? Default is false.
        -->
        <init-param>
            <param-name>cookie-http-only</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Are you debugging? Default is false.
        -->
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>
        <!--
            Configuration xml location;
                * as servlet resource OR
                * as classpath resource OR
                * as URL
            Default is one of hazelcast-default.xml
            or hazelcast.xml in classpath.
        -->
    
        <init-param>
            <param-name>config-location</param-name>
            <param-value>/WEB-INF/classes/hazelcast.xml</param-value>
        </init-param>
    
        <!--
            Do you want to use an existing HazelcastInstance?
            Default is null.
        -->`enter code here`
        <init-param>
            <param-name>instance-name</param-name>
            <param-value>myapp</param-value>
        </init-param>
        <!--
            Do you want to connect as a client to an existing cluster?
            Default is false.
        -->
        <init-param>
            <param-name>use-client</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Client configuration location;
                * as servlet resource OR
                * as classpath resource OR
                * as URL
            Default is null.
        -->
        <init-param>
            <param-name>client-config-location</param-name>
            <param-value>/WEB-INF/classes/hazelcast-client.properties</param-value>
        </init-param>
            <!--
                Do you want to shutdown HazelcastInstance during
                web application undeploy process?
                Default is true.
            -->
            <init-param>
                <param-name>shutdown-on-destroy</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>hazelcast-filter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>INCLUDE</dispatcher>
            <dispatcher>REQUEST</dispatcher>
        </filter-mapping>
    
    ...
    
    </web-app>
    

    hazelcast.xml (jar 파일 안의 hazelcast.xml에서 복사) ...

    <hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-2.4.xsd"
               xmlns="http://www.hazelcast.com/schema/config"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    ...
    <network>
        <port auto-increment="true">5701</port>
        <outbound-ports>
            <!--
            Allowed port range when connecting to other nodes.
            0 or * means use system provided port.
            -->
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="false">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>
            <tcp-ip enabled="false">
                <interface>127.0.0.1</interface>
            </tcp-ip>
     ...
        </join>
     ...
    </network>
    
    ...  
    
    </hazelcast>
    

    봄 설정 ....

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hz="http://www.hazelcast.com/schema/spring"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.hazelcast.com/schema/spring
    http://www.hazelcast.com/schema/spring/hazelcast-spring-2.4.xsd">
    
    
    <bean id="hazelcast" class="com.hazelcast.core.Hazelcast" />
    
    <!-- Hazelcast Instance configuration -->
    <hz:hazelcast id="myapp">
        <hz:config>
            <!-- Hazelcast Instance Name -->
            <hz:instance-name>${hz.instance.name}</hz:instance-name>
            <!-- Hazelcast Group Name and Password -->
            <hz:group name="${hz.group.name}" password="${hz.group.password}" />
            <!-- Hazelcast Management Center URL -->
            <hz:management-center enabled="${hz.management.center.enabled}" url="${hz.management.center.url}" />
            <!-- Hazelcast Tcp based network configuration -->
            <hz:network port="${hz.network.port}" port-auto-increment="${hz.network.port.auto.increment}">
                <hz:join>
                    <hz:multicast enabled="${hz.multicast.enabled}" multicast-group="224.2.2.3" multicast-port="54327" />
                    <hz:tcp-ip enabled="${hz.tcp.ip.enabled}">
                        <hz:members>${hz.members}</hz:members>
                    </hz:tcp-ip>
                </hz:join>
            </hz:network>
            <!-- Hazelcast Distributed Map configuration -->
            <hz:map name="map" backup-count="${hz.map.backup.count}" max-size="${hz.map.max.size}" eviction-percentage="${hz.map.eviction.percentage}"
                read-backup-data="${hz.map.read.backup.data}" eviction-policy="${hz.map.eviction.policy}" merge-policy="${hz.map.merge.policy}" />
        </hz:config>
    </hz:hazelcast>
    

    속성 파일 ....

    #-- Hazelcast properties.
    hz.instance.name = myapp
    hz.group.name = CERT
    hz.group.password = cert
    hz.management.center.enabled = true
    hz.management.center.url = http://127.0.0.1:8080/mancenter
    hz.network.port = 5701
    hz.network.port.auto.increment = true
    hz.multicast.enabled = true
    hz.tcp.ip.enabled = false
    hz.members = 127.0.0.1
    hz.executor.service.core.pool.size = 2
    hz.executor.service.max.pool.size = 30
    hz.executor.service.keep.alive.seconds = 30
    hz.map.backup.count=2
    hz.map.max.size=0
    hz.map.eviction.percentage=30
    hz.map.read.backup.data=true
    hz.map.cache.value=true
    hz.map.eviction.policy=NONE
    hz.map.merge.policy=hz.ADD_NEW_ENTRY
    

    루트 Context.xml

    <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:hz="http://www.hazelcast.com/schema/spring"
        xmlns:jee="http://www.springframework.org/schema/jee" 
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
        http://www.hazelcast.com/schema/spring
        http://www.hazelcast.com/schema/spring/hazelcast-spring-2.4.xsd">
    
    
    ...
    
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <jee:jndi-lookup jndi-name="java:comp/env/config_file" />
                </list>
            </property>
        </bean>
    
    ...
    
    </beans>    
    

    Tomcat 구성 ...

    <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    ...
    
        <Context docBase="myapp" path="/myapp" reloadable="true"  source="org.eclipse.jst.j2ee.server:pwc-ws">
                        <Environment description="" name="config_file" override="false" type="java.lang.String" value="file:c:/path/to/config/myapp.properties" />
            </Context>
    ...
    
    </Host>
    

    Tomcat 출력 (참고 : 두 노드 hazelcast 그룹의 재시작 시나리오입니다.이 시나리오에서는 노드 1이 다시 시작됩니다. 노드 2의 출력에는 그룹에서 노드 1이 드롭 된 다음 그룹으로 리턴됩니다).

    그룹 CERT의 노드 1

    Nov 19, 2013 4:27:56 PM com.hazelcast.impl.AddressPicker
    INFO: Prefer IPv4 stack is true.
    Nov 19, 2013 4:27:56 PM com.hazelcast.impl.AddressPicker
    INFO: Picked Address[10.23.43.13]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
    Nov 19, 2013 4:27:57 PM com.hazelcast.system
    INFO: [10.23.43.13]:5701 [CERT] Hazelcast Community Edition 2.4 (20121017) starting at Address[10.23.43.13]:5701
    Nov 19, 2013 4:27:57 PM com.hazelcast.system
    INFO: [10.23.43.13]:5701 [CERT] Copyright (C) 2008-2012 Hazelcast.com
    Nov 19, 2013 4:27:57 PM com.hazelcast.impl.LifecycleServiceImpl
    INFO: [10.23.43.13]:5701 [CERT] Address[10.23.43.13]:5701 is STARTING
    Nov 19, 2013 4:27:57 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:57 PM com.hazelcast.impl.MulticastJoiner
    INFO: [10.23.43.13]:5701 [CERT] Connecting to master node: Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:57 PM com.hazelcast.nio.ConnectionManager
    INFO: [10.23.43.13]:5701 [CERT] 54106 accepted socket connection from /10.23.43.14:5701
    Nov 19, 2013 4:27:57 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:57 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:58 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:58 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:59 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:27:59 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:00 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:00 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:01 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:01 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:02 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:02 PM com.hazelcast.impl.Node
    INFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701
    Nov 19, 2013 4:28:02 PM com.hazelcast.cluster.ClusterManager
    INFO: [10.23.43.13]:5701 [CERT]
    
    Members [2] {
            Member [10.23.43.14]:5701
            Member [10.23.43.13]:5701 this
    }
    
    Nov 19, 2013 4:28:04 PM com.hazelcast.impl.LifecycleServiceImpl
    INFO: [10.23.43.13]:5701 [CERT] Address[10.23.43.13]:5701 is STARTED
    Nov 19, 2013 4:28:04 PM com.hazelcast.impl.management.ManagementCenterService
    INFO: [10.23.43.13]:5701 [CERT] Hazelcast will connect to Management Center on address:     http://localhost:8080/mancenter/
    Nov 19, 2013 4:28:04 PM com.hazelcast.config.UrlXmlConfig
    INFO: Configuring Hazelcast from 'jndi:/localhost/pwc-ui/WEB-INF/classes/hazelcast.xml'.
    Nov 19, 2013 4:28:04 PM com.hazelcast.web.WebFilter
    INFO: sticky:true, debug: true, shutdown-on-destroy: true, map-name: my-sessions
    Nov 19, 2013 4:28:05 PM org.apache.catalina.startup.HostConfig deployDescriptor
    

    그룹 CERT의 노드 2 (드롭 및 다시 추가)

    Nov 19, 2013 4:27:11 PM com.hazelcast.nio.Connection
    INFO: [10.23.43.14]:5701 [CERT] Connection [Address[10.23.43.13]:5701] lost. Reason: java.io.IOException[Connection reset by peer]
    Nov 19, 2013 4:27:11 PM com.hazelcast.nio.ReadHandler
    WARNING: [10.23.43.14]:5701 [CERT] hz.pwc.IO.thread-1 Closing socket to endpoint Address[10.23.43.13]:5701, Cause:java.io.IOException: Connection reset by peer
    Nov 19, 2013 4:27:12 PM com.hazelcast.nio.SocketConnector
    INFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]
    Nov 19, 2013 4:27:13 PM com.hazelcast.nio.SocketConnector
    INFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]
    Nov 19, 2013 4:27:14 PM com.hazelcast.nio.SocketConnector
    INFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]
    Nov 19, 2013 4:27:14 PM com.hazelcast.nio.ConnectionMonitor
    WARNING: [10.23.43.14]:5701 [CERT] Removing connection to endpoint Address[10.23.43.13]:5701 Cause => java.net.ConnectException {Connection refused}, Error-Count: 5
    Nov 19, 2013 4:27:14 PM com.hazelcast.cluster.ClusterManager
    INFO: [10.23.43.14]:5701 [CERT] Removing Address Address[10.23.43.13]:5701
    Nov 19, 2013 4:27:14 PM com.hazelcast.impl.PartitionManager
    INFO: [10.23.43.14]:5701 [CERT] Starting to send partition replica diffs...true
    Nov 19, 2013 4:27:14 PM com.hazelcast.cluster.ClusterManager
    INFO: [10.23.43.14]:5701 [CERT]
    
    Members [1] {
            Member [10.23.43.14]:5701 this
    }
    
    Nov 19, 2013 4:27:18 PM com.hazelcast.impl.PartitionManager
    INFO: [10.23.43.14]:5701 [CERT] Total 0 partition replica diffs have been processed.
    Nov 19, 2013 4:27:18 PM com.hazelcast.impl.PartitionManager
    INFO: [10.23.43.14]:5701 [CERT] Re-partitioning cluster data... Immediate-Tasks: 0, Scheduled-Tasks: 0
    Nov 19, 2013 4:27:57 PM com.hazelcast.nio.SocketAcceptor
    INFO: [10.23.43.14]:5701 [CERT] 5701 is accepting socket connection from /10.23.43.13:54106
    Nov 19, 2013 4:27:57 PM com.hazelcast.nio.ConnectionManager
    INFO: [10.23.43.14]:5701 [CERT] 5701 accepted socket connection from /10.23.43.13:54106
    Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilter
    INFO: Created new session with id: HZ650FDF62693F45A99AC0C30BBD8840B0
    Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilter
    INFO: 195 is sessions.size and originalSessions.size: 195
    Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilter
    INFO: PUTTING SESSION HZ650FDF62693F45A99AC0C30BBD8840B0
    Nov 19, 2013 4:28:02 PM com.hazelcast.cluster.ClusterManager
    INFO: [10.23.43.14]:5701 [CERT]
    
    Members [2] {
            Member [10.23.43.14]:5701 this
            Member [10.23.43.13]:5701
    }
    
    Nov 19, 2013 4:28:02 PM com.hazelcast.impl.PartitionManager
    INFO: [10.23.43.14]:5701 [CERT] Re-partitioning cluster data... Immediate-Tasks: 271, Scheduled-Tasks: 0
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: Created new session with id: HZAD50E5F483CC448C9FA7CB66D65848BB
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: 196 is sessions.size and originalSessions.size: 196
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: PUTTING SESSION HZAD50E5F483CC448C9FA7CB66D65848BB
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: Created new session with id: HZC9553A4C330044CA8A0C20549EE23BF0
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: 197 is sessions.size and originalSessions.size: 197
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: PUTTING SESSION HZC9553A4C330044CA8A0C20549EE23BF0
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilter
    INFO: Request is instance of RequestWrapper! Continue...
    10069.275: [GC [PSYoungGen: 693173K->3458K(695488K)] 877908K->188718K(2093632K), 0.0224650 secs] [Times: user=0.04 sys=0.00, real=0.02 secs]
    Nov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilter
    INFO: Created new session with id: HZE46365454C2C45F98A7947AC40E404BB
    Nov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilter
    INFO: 198 is sessions.size and originalSessions.size: 198
    Nov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilter
    INFO: PUTTING SESSION HZE46365454C2C45F98A7947AC40E404BB
    
  2. ==============================

    2.다음은 Hazelcast 3.2-SNAPSHOT에서만 작동합니다.

    다음은 Hazelcast 3.2-SNAPSHOT에서만 작동합니다.

    세션 복제와 응용 프로그램간에 공유되는 단일 HazelcastInstance로 시작하십시오. 다음과 같이 할 수 있습니다.

    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);
        }
    }
    

    이제 스프링 구성 :

    <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>
    

    그래서 이것이로드 될 때 HazelcastInstance라는 'default'라는 이름이 붙습니다.

    다음과 같이 세션 복제를 구성 할 때 :

    <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>
    

    그런 다음 세션 필터는 해당 이름의 hazelcast 인스턴스를로드하려고 시도합니다. Spring applicationcontext가로드되었으므로 'default'HazelcastInstance가 이미 생성 되었기 때문에 세션 필터는 해당 인스턴스를 사용하고 새로운 인스턴스를 생성하지 않습니다.

    구성 파일을 완전히 분리해야하는 경우 'hazelcast.conf'시스템 속성을 사용하여 파일을 지정하면됩니다 (HazelcastInstanceLoader 코드 참조). 시스템 프로퍼티에 의존하는 대신 HazelcastInstanceLoader.load 메소드를 수정하여 'path'속성을 받아 들일 수 있습니다.이 속성은 Spring에서 삽입 할 수 있습니다.

    다른 환경에 대해 서로 다른 그룹을 설정하는 것은 이러한 환경의 시스템이 그룹을 형성하지 못하도록하는 유용한 방법입니다. 그러나 구성을 공유하고 세부 사항에만 차이점 (예 : 그룹 이름)이있는 경우 xml에서 변수를 사용할 수도 있습니다.

    <hazelcast>
        <group>
           <name>${groupname}</name>
           <password>${password}</password>
        </group>
        ...
     </hazelcast>
    

    이 질문에 대한 대답입니까?

  3. ==============================

    3.왜 src / main / resources에 환경마다 파일을 넣지 않는가? 그래서 당신은 : dev.properties, qa.properties, prod.properties

    왜 src / main / resources에 환경마다 파일을 넣지 않는가? 그래서 당신은 : dev.properties, qa.properties, prod.properties

    ENV와 같은 환경 변수를 사용하십시오. 내 상황에서 ENV = dev을 넣었습니다. 그리고 나서 내 spring-servlet.xml 안에있다.

    <property name="locations">
        <list>
            <value>classpath:/${SERVER_ENV}.hazelcast.properties</value>
        </list>
    </property>
    

    그리고 같은 파일에서이 방법으로 속성을 사용합니다.

    <hz:hazelcast id="myapp">
            <hz:config>
                <!-- Hazelcast Instance Name -->
                <hz:instance-name>${hz.instance.name}</hz:instance-name>
                <!-- Hazelcast Group Name and Password -->
                <hz:group name="${hz.group.name}" password="${hz.group.password}" />
                <!-- Hazelcast Management Center URL -->
                <hz:management-center enabled="${hz.management.center.enabled}" url="${hz.management.center.url}"
                    />
                <!-- Hazelcast Tcp based network configuration -->
                <hz:network port="${hz.network.port}" port-auto-increment="${hz.network.port.auto.increment}">
                    <hz:join>
                        <hz:multicast enabled="${hz.multicast.enabled}" multicast-group="224.2.2.3" multicast-port="54327"
                            />
                        <hz:tcp-ip enabled="${hz.tcp.ip.enabled}">
                            <hz:members>${hz.members}</hz:members>
                        </hz:tcp-ip>
                    </hz:join>
                </hz:network>
                <!-- Hazelcast Distributed Map configuration -->
                <hz:map name="map" backup-count="${hz.map.backup.count}" max-size="${hz.map.max.size}"
                    eviction-percentage="${hz.map.eviction.percentage}" read-backup-data="${hz.map.read.backup.data}"
                    eviction-policy="${hz.map.eviction.policy}" merge-policy="${hz.map.merge.policy}"
                    />
            </hz:config>
        </hz:hazelcast>
    
  4. from https://stackoverflow.com/questions/19868694/how-to-configure-hazelcast-for-session-caching-using-spring-while-limiting-it-to by cc-by-sa and MIT license