Forum: Building VoltDB Clients

Post: Spring connection configuration

Spring connection configuration
kdombeck
Nov 2, 2010
Do you have example of creating a Client connection via Spring?
Since we use Spring for our dependency injection it would be nice to have an example for this. I think I have figured out how to do it but it is kind of ugly since Client.createConnection takes parameters rather than setting properties and creating a connection.
You're right - we haven't
rbetts
Nov 4, 2010
You're right - we haven't arranged a lot of our java code around the common bean getter/setter conventions. We don't use Spring internally and unfortunately I don't have a good example. Short of wrapping Client to provide a spring-friendly interface, I don't have a particularly great suggestion...
Anyone reading with a better answer? Would love to hear your comments on Spring and Client.
*--Ryan.
Spring config
kdombeck
Nov 12, 2010
You're right - we haven't arranged a lot of our java code around the common bean getter/setter conventions. We don't use Spring internally and unfortunately I don't have a good example. Short of wrapping Client to provide a spring-friendly interface, I don't have a particularly great suggestion...
Anyone reading with a better answer? Would love to hear your comments on Spring and Client.
*--Ryan.


I found this configuration to work for me.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="config" class="org.voltdb.client.ClientConfig">
<constructor-arg value="myUserName"/>
<constructor-arg value="myPassword"/>
</bean>
<bean id="client" class="org.voltdb.client.ClientFactory" factory-method="createClient">
<constructor-arg ref="config"/>
</bean>
<bean id="clientCreateConnection" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="client"/>
<property name="targetMethod" value="createConnection"/>
<property name="arguments">
<list>
<value>localhost</value>
<value>21212</value>
</list>
</property>
</bean>
<bean id="myBean" class="com.my.company.MyBeanImpl">
<property name="client" ref="client"/>
</bean>
</beans>