Results 1 to 3 of 3

Thread: Configure complex object in xml to inject.

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Default Configure complex object in xml to inject.

    --------------------------------------------------------------------
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster("ClusterName")
    .forKeyspace("KeyspaceName")
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool" )
    .setPort(9160)
    .setSeeds("127.0.0.1:9160")
    )
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    Keyspace keyspace = context.getEntity();
    --------------------------------------------------------------------
    I need to inject Keyspace instance in spring and need to configure it in applicationContext.xml.
    Can anyone tell me how to do it? it is really complex. thanks.

  2. #2
    Join Date
    Dec 2009
    Location
    India
    Posts
    108

    Smile This is straight forward. Read the spring documentation on FactoryBean for details.

    You need to create a FactoryBean for this. Roughly the class should look something like this

    Code:
    public class KeyspaceFactoryBean<Keyspace> implements FactoryBean<Keyspace> {
    private String clusterName;
    private String keyspaceName;
    private String connectionPoolName;
    private int portNo;
    private String seeds;
    public String getSeeds() {
    return seeds;
    }
    public void setSeeds(String seeds) {
    this.seeds = seeds;
    }
    public int getPortNo() {
    return portNo;
    }
    public void setPortNo(int portNo) {
    this.portNo = portNo;
    }
    public void setConnectionPoolName(String name) {
    this.connectionPoolName = name;
    }
    public String getConnectionPoolName() {
    return this.connectionPoolName;
    }
    public String getKeyspaceName() {
    return this.keyspaceName;
    }
    public void setKeyspaceName(String name) {
    this.keyspaceName = name;
    }
    public void setClusterName(String name) {
    this.clusterName = name;
    }
    public String getClusterName() {
    return this.clusterName;
    }
    public Keyspace getObject() throws Exception {
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster(clusterName)
    .forKeyspace(keyspaceName)
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(connectionPoolName )
    .setPort(portNo)
    .setSeeds(seeds)
    )
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());
    
    context.start();
    Keyspace keyspace = context.getEntity();
    return keyspace;
    }
    }
    now this can be declared inside your XML Configuration like this

    Code:
    <bean id="keyspace" class="KeyspaceFactoryBean">
    <property name="clusterName" value="clusterName" />
    <property name="keyspaceName" value="keyspaceName" />
    <property name="connectionPoolName" value="connectionPoolName" />
    <property name="clusterName" value="clusterName" />
    <property name="portNo" value="9110" />
    <property name="seeds" value="someAppropriateSeedsValue" />
    </bean>
    As suggested

  3. #3
    Join Date
    Jan 2013
    Posts
    1

    Default

    Hi,

    Is there a way to dynamically set KeyspaceFactoryBean properties from the client when it asks the context for a new instance?

    Thanks a lot,

    Max

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •