Spring integrated redis detailed code example

This article introduces an example of spring integrating redis from the beginning.

Eclipse engineering structure

The following figure is the structure diagram of my example project, which is built by Maven. Spring needs to be integrated, so beans XML file to configure the dependency injection of spring, redis Properties configures the configuration information of the connection server.

Among them, beans XML and redis The properties file is directly placed in the root directory. Readers who need it can put it in the resource directory.

POM dependency

The following are examples of POM dependencies. The packages that spring needs to rely on to integrate redis are: jedis package, spring context module and dependent package, spring data redis module package, spring test package for JUnit test, POM The contents of the XML file are as follows:

Spring configuration

Spring configuration file beans XML is configured as follows:

In beans In the XML configuration file, redis.xml needs to be loaded first Properties file.

Redis configuration information

Redis configuration information is available in redis Configuration in the properties file:

In this example, the connection password is not set when connecting to the redis server, so there is no need to fill in the value.

Java code

User. java

AbstractRedisBaseDao. java

IUserDao. java

UserDao. java

RedisTest. Java (JUnit test class)

summary

The above is all about the detailed code example of spring integration redis in this article. I hope it will be helpful to you. Interested friends can continue to refer to this website:

Comments on spring

Factorybean code example in spring

Two configuration containers of spring

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>