在集群环境中使用jboss缓存来休眠二级缓存

时间:2013-06-03 13:31:20

标签: java spring-3 hibernate3 jboss-cache jboss-eap-4.3.x

您好我在我的项目中使用了以下

  1. jboss服务器(4.3 EAP)的'all'配置
  2. spring 3.0
  3. hibernate 3.0
  4. jboss cache 1.x
  5. 启用二级缓存的 applicationContext.xml片段

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
             <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.cache.provider_class">
                org.hibernate.cache.TreeCacheProvider
            </prop>
        </props>
        </property> 
    

    事务管理器的 applicationContext.xml 的片段是

    <bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:/TransactionManager" />
        <property name="userTransactionName" value="UserTransaction" />
        <property name="allowCustomIsolationLevels">
            <value>true</value>
        </property>
    </bean>
    

    treecache.xml 的内容是

    <server>
        <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
        <mbean code="org.jboss.cache.TreeCache" name="jboss.cache:service=MyTreeCache">
            <depends>jboss:service=Naming</depends>
            <depends>jboss:service=TransactionManager</depends>
            <attribute name="TransactionManagerLookupClass">
                org.jboss.cache.GenericTransactionManagerLookup 
            </attribute>
            <attribute name="ClusterName">MyPartition</attribute>
            <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
            <attribute name="CacheMode">REPL_SYNC</attribute>
            <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
            <attribute name="FetchInMemoryState">false</attribute>
            <attribute name="InitialStateRetrievalTimeout">20000</attribute>
            <attribute name="SyncReplTimeout">20000</attribute>
            <attribute name="LockAcquisitionTimeout">15000</attribute>
            <attribute name="ClusterConfig">
                <config>
                    <UDP loopback="true" />
                    <PING timeout="2000" num_initial_members="3" up_thread="false"
                        down_thread="false" />
                    <FD_SOCK />
                    <pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
                        max_xmit_size="8192" up_thread="false" down_thread="false" />
                    <UNICAST timeout="600,1200,2400" window_size="100"
                        min_threshold="10" down_thread="false" />
                    <pbcast.STABLE desired_avg_gossip="20000" up_thread="false"
                        down_thread="false" />
                    <FRAG frag_size="8192" down_thread="false" up_thread="false" />
                    <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
                        shun="true" print_local_addr="true" />
                    <pbcast.STATE_TRANSFER up_thread="true"
                        down_thread="true" />
                </config>
            </attribute>
        </mbean>
    </server>
    

    并使用以下命令启动节点

    run.bat -c node11 -g MyPartition -u 239.255.100.100 -Djboss.service.binding.set = ports-default

    然后它会抛出以下异常

    18:51:16,303 ERROR [TreeCache] Caught exception registering channel in JXM
    javax.management.InstanceAlreadyExistsException: jboss.jgroups:type=protocol,cluster=My
    tition,protocol=STATE_TRANSFER already registered.
            at org.jboss.mx.server.registry.BasicMBeanRegistry.add(BasicMBeanRegistry.java:
    )
            at org.jboss.mx.server.registry.BasicMBeanRegistry.registerMBean(BasicMBeanRegi
    y.java:225)
            at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java
    3)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOpe
    ionInterceptor.java:142)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.server.MBeanServerImpl$3.run(MBeanServerImpl.java:1422)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:1417)
            at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:376)
            at org.jgroups.jmx.JmxConfigurator.registerProtocols(JmxConfigurator.java:108)
            at org.jboss.cache.TreeCache.registerChannelInJmx(TreeCache.java:6730)
            at org.jboss.cache.TreeCache._createService(TreeCache.java:1477)
            at org.jboss.cache.TreeCache.createService(TreeCache.java:1389)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport
    va:260)
            at org.jboss.system.ServiceMBeanSupport.create(ServiceMBeanSupport.java:188)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.
    a:280)
            at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:196)
            at org.hibernate.cache.TreeCacheProvider.start(TreeCacheProvider.java:75)
            at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
            at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory
    calSessionFactoryBean.java:860)
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFacto
    LocalSessionFactoryBean.java:779)
            at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertie
    t(AbstractSessionFactoryBean.java:188)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    vokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    itializeBean(AbstractAutowireCapableBeanFactory.java:1452)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    CreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    eateBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Ab
    actBeanFactory.java:294)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi
    eton(DefaultSingletonBeanRegistry.java:225)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abst
    tBeanFactory.java:291)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstra
    eanFactory.java:193)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAut
    reCandidates(DefaultListableBeanFactory.java:848)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResol
    ependency(DefaultListableBeanFactory.java:790)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolve
    endency(DefaultListableBeanFactory.java:707)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
    or$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
            at org.springframework.beans.factory.annotation.InjectionMetadata.inject(Inject
    Metadata.java:87)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc
    or.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    pulateBean(AbstractAutowireCapableBeanFactory.java:1106)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    CreateBean(AbstractAutowireCapableBeanFactory.java:517)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
    eateBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Ab
    actBeanFactory.java:294)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi
    eton(DefaultSingletonBeanRegistry.java:225)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abst
    tBeanFactory.java:291)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstra
    eanFactory.java:193)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInst
    iateSingletons(DefaultListableBeanFactory.java:585)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFac
    yInitialization(AbstractApplicationContext.java:913)
            at org.springframework.context.support.AbstractApplicationContext.refresh(Abstr
    ApplicationContext.java:464)
            at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicat
    Context(ContextLoader.java:385)
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(Cont
    Loader.java:284)
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(Con
    tLoaderListener.java:111)
            at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:
    4)
            at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:7
    
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:732)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297
            at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.apache.catalina.core.StandardContext.init(StandardContext.java:5263)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297
            at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDepl
    r.java:295)
            at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.jav
    08)
            at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
            at org.jboss.web.WebModule.startModule(WebModule.java:83)
            at org.jboss.web.WebModule.startService(WebModule.java:61)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.
    a:289)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupp
    .java:245)
            at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.jav
    78)
            at $Proxy0.start(Unknown Source)
            at org.jboss.system.ServiceController.start(ServiceController.java:417)
            at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            at $Proxy53.start(Unknown Source)
            at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java
    3)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOpe
    ionInterceptor.java:142)
            at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:9
            at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServic
    eanSupport.java:238)
            at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerIntercepto
    ava:87)
            at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(S
    eployerInterceptorSupport.java:188)
            at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.ja
    95)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            at $Proxy54.start(Unknown Source)
            at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
            at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java
    3)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOpe
    ionInterceptor.java:142)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            at $Proxy9.deploy(Unknown Source)
            at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanne
    ava:421)
            at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.
    a:634)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(
    tractDeploymentScanner.java:266)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(Abstract
    loymentScanner.java:344)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.
    a:289)
            at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupp
    .java:245)
            at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.jav
    78)
            at $Proxy0.start(Unknown Source)
            at org.jboss.system.ServiceController.start(ServiceController.java:417)
            at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            at $Proxy4.start(Unknown Source)
            at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
            at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    va:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java
    5)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java
    3)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOpe
    ionInterceptor.java:142)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:26
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            at $Proxy5.deploy(Unknown Source)
            at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
            at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
            at org.jboss.Main.boot(Main.java:200)
            at org.jboss.Main$1.run(Main.java:518)
            at java.lang.Thread.run(Thread.java:722)
    18:51:18,639 INFO  [STDOUT]
    

    我在这里做错了可以有人建议我。 任何帮助将受到高度赞赏

1 个答案:

答案 0 :(得分:1)

我相信你的问题是你有2个jgroups集群设置(app服务器的集群和treecache的集群),两个集群都有相同的分区名称“MyPartition”。您需要为treecache群集配置配置不同的分区名称。