2017-07-27 99 views
0

我創建了一個使用spring,hibernate,jpa的Hazelcast管理器。我可以開始我的榛子實例。Hazelcast客戶端彈簧配置

我遇到的問題是我不知道如何配置使用spring配置的榛樹客戶端。我想在一些其他的服務器組件hazelcast客戶端

我真的不知道用怎樣開始

任何幫助,將不勝感激

下面是我對hazelcast服務器Spring配置

約翰

<?xml version="1.0" encoding="UTF-8"?> 
<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:tx="http://www.springframework.org/schema/tx" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context.xsd 
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd 
          http://www.hazelcast.com/schema/spring 
          http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd"> 

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>file:${ecs.config.path}/ecs.properties</value> 
       <value>classpath*:config/ecs.properties</value> 
      </list> 
     </property> 
     <property name="ignoreUnresolvablePlaceholders" value="true"/> 
     <property name="ignoreResourceNotFound" value="true" /> 
    </bean> 

    <context:component-scan base-package="nl.ict.psa.ecs.hazelcast.dao,nl.ict.psa.ecs.hazelcast.mapstores,nl.ict.psa.ecs.hazelcast.service" /> 

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="${datasource.driverClassName}" /> 
     <property name="url" value="${datasource.url}" /> 
     <property name="username" value="${datasource.username}"/> 
     <property name="password" value="${datasource.password}"/> 
    </bean> 

    <bean id="hazelcast" class="com.hazelcast.core.Hazelcast"/> 

    <bean id="entityManagerFactoryBean" 
     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 

     <property name="dataSource" ref="dataSource" /> 
     <property name="persistenceUnitName" value="PU" /> 
     <property name="packagesToScan"> 
      <list> 
       <value>nl.ict.psa.hazelcast.model.ecs</value> 
       <value>nl.ict.psa.hazelcast.model.ecs.ocr</value> 
      </list> 
     </property> 
     <property name="jpaVendorAdapter"> 
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> 
     </property> 
     <property name="jpaProperties"> 
      <props> 
       <prop key="hibernate.archive.autodetection">class</prop> 
       <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> 
       <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
      </props> 
     </property> 
    </bean> 

    <tx:annotation-driven /> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactoryBean" /> 
    </bean> 

    <bean id="transpInfo" class="nl.ict.psa.ecs.hazelcast.mapstores.TranspInfoMapStore"/> 

    <hz:hazelcast id="instance"> 
     <hz:config> 
      <hz:network port="5701" port-auto-increment="true"> 
       <hz:join> 
        <hz:multicast enabled="false"/> 
       </hz:join> 
      </hz:network> 

      <hz:map name="transp" read-backup-data="true"> 
       <hz:map-store enabled="true" write-delay-seconds="60" 
           initial-mode="LAZY" 
           implementation="transpInfo"/> 
      </hz:map> 
     </hz:config> 
    </hz:hazelcast> 

</beans> 

回答

0

像這樣的東西(從https://github.com/neilstevenson/spring-boot-autoconfigure-test/tree/master/hazelcast-imdg-client

@Configuration 
@ConditionalOnMissingBean(ClientConfig.class) 
static class HazelcastClientConfigConfiguration { 

    @Bean 
    public ClientConfig clientConfig() throws Exception { 
      return new XmlClientConfigBuilder().build(); 
    } 
} 

@Configuration 
@ConditionalOnMissingBean(HazelcastInstance.class) 
static class HazelcastClientConfiguration { 

    @Bean 
    public HazelcastInstance hazelcastInstance(ClientConfig clientConfig) { 
     return HazelcastClient.newHazelcastClient(clientConfig); 
    } 
} 

```

儘量避免XML,春天遠離它。