Blankman
Blankman

Reputation: 266988

Using jedis with spring, but not with spring-data lib, where to store pool?

In the jedis docs it says to create a pool:

JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");

And that I should be storing this statically somewhere.

I know spring has a spring-data library that is in development, but I just want to use the library w/o that for now.

Where do you suggest I create this static reference to the pool?

Should I create a JedisService and then have a public method that returns this pool?

Do I do this using the singleton pattern? lock before returning?

Upvotes: 1

Views: 1422

Answers (1)

duffymo
duffymo

Reputation: 308753

If you're using Spring, you can't use new and have the object under Spring's control. Make it a Spring bean and initialize it using a factory method.

You declare beans in your Spring application context XML (or using annotations, if you're so inclined):

<bean id="jedisPool" class="foo.bar.JedisPool">
    <constructor-arg ref="jedisPoolCofig"/>
    <constructor-arg value="localhost"/
</bean>

Upvotes: 1

Related Questions