Clients im Spring-Framework konfigurieren

Sie können clientseitige ObjectGrid-Einstellungen mit dem Spring-Framework überschreiben.

Informationen zu diesem Vorgang

Die folgende XML-Beispieldatei veranschaulicht, wie ein Element "ObjectGridConfiguration" erstellt und zum Überschreiben einige clientseitiger Einstellungen verwendet wird. Sie können eine ähnliche Konfiguration durch programmgesteuerte Konfiguration oder durch Konfiguration der ObjectGrid-XML-Deskriptordatei erstellen.

[Version 8.5 und höher] Informationen zur Verwendung der Beans "ObjectGridClientBean" und "ObjectGridCatalogServiceDomainBean" für die Unterstützung der Cacheabstraktion von Spring Framework Version 3.1 finden Sie unter Spring-Cache-Provider konfigurieren.

Vorgehensweise

  1. Erstellen Sie eine XML-Datei, um Clients mit dem Spring-Framework zu konfigurieren.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    		"http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
      <bean id="companyGrid" factory-bean="manager" factory-method="getObjectGrid"
        singleton="true">
        <constructor-arg type="com.ibm.websphere.objectgrid.ClientClusterContext">
          <ref bean="client" />
        </constructor-arg>
        <constructor-arg type="java.lang.String" value="CompanyGrid" />
    </bean>
    
      <bean id="manager" class="com.ibm.websphere.objectgrid.ObjectGridManagerFactory"
        factory-method="getObjectGridManager" singleton="true">
        <property name="overrideObjectGridConfigurations">
          <map>
            <entry key="DefaultDomain">
              <list>
                <ref bean="ogConfig" />
              </list>
            </entry>
          </map>
        </property>
      </bean>
    
      <bean id="ogConfig"
        class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
        factory-method="createObjectGridConfiguration">
        <constructor-arg type="java.lang.String">
          <value>CompanyGrid</value>
        </constructor-arg>
        <property name="plugins">
          <list>
    	  <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
              factory-method="createPlugin">
              <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
                value="TRANSACTION_CALLBACK" />
              <constructor-arg type="java.lang.String"
                value="com.company.MyClientTxCallback" />
            </bean>
            <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
              factory-method="createPlugin">
              <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
                value="OBJECTGRID_EVENT_LISTENER" />
              <constructor-arg type="java.lang.String" value="" />
            </bean>
          </list>
    	</property>
          <property name="backingMapConfigurations">
            <list>
    	    <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                factory-method="createBackingMapConfiguration">
                <constructor-arg type="java.lang.String" value="Customer" />
                  <property name="plugins">
    		    <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                      factory-method="createPlugin">
                      <constructor-arg type="com.ibm.websphere.objectgrid.config.PluginType"
    			  value="EVICTOR" />
    			<constructor-arg type="java.lang.String"
                        value="com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor" />
                    </bean>
                  </property>
                  <property name="numberOfBuckets" value="1429" />
                </bean>
                <bean class="com.ibm.websphere.objectgrid.config.ObjectGridConfigFactory"
                  factory-method="createBackingMapConfiguration">
                    <constructor-arg type="java.lang.String" value="OrderLine" />
                      <property name="numberOfBuckets" value="701" />
    			<property name="timeToLive" value="800" />
    			<property name="ttlEvictorType">
                        <value type="com.ibm.websphere.objectgrid.
    											TTLType">LAST_ACCESS_TIME</value>
    			</property>
                </bean>
              </list>
            </property>
          </bean>
    
          <bean id="client" factory-bean="manager" factory-method="connect"
            singleton="true">
            <constructor-arg type="java.lang.String">
    	    <value>localhost:2809</value>
            </constructor-arg>
    	  <constructor-arg
              type="com.ibm.websphere.objectgrid.security.
    						config.ClientSecurityConfiguration">
              <null />
            </constructor-arg>
    	  <constructor-arg type="java.net.URL">
    	    <null />
            </constructor-arg>
          </bean>
    </beans>
  2. Laden Sie die erstellte XML-Datei, und erstellen Sie das ObjectGrid.
    BeanFactory beanFactory = new XmlBeanFactory(newUrlResource
    		("file:test/companyGridSpring.xml"));
    ObjectGrid companyGrid = (ObjectGrid) beanFactory.getBean("companyGrid");

    Weitere Informationen zum Erstellen einer XML-Deskriptordatei finden Sie unter Übersicht über das Spring-Framework.