spring-data spring 的nosql的orm框架学习
来源:互联网 发布:手机淘宝怎么设置首页 编辑:程序博客网 时间:2024/05/29 08:35
使用了spring-data-redis对于redis的orm框架的学习,整理了一下的使用文档
1.在pom.xml添加一下依赖:
<dependencies><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>1.0.0.RC1</version></dependency></dependencies><repositories><repository><id>spring-milestone</id><name>Spring Maven MILESTONE Repository</name><url>http://maven.springframework.org/milestone</url></repository></repositories>
执行mvn eclipse:eclipse引入依赖包
2.在工程的classpath目录添加spring的配置文件spring-redis.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="jedisFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="10.20.150.206" p:port="6379"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisFactory"/></beans>
redis服务器的地址改为对应的服务化端口和地址
3.编写测试类代码:
import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.data.redis.core.BoundListOperations;import org.springframework.data.redis.core.BoundValueOperations;import org.springframework.data.redis.core.RedisTemplate;public class SpringDataRedis {public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-redis.xml");RedisTemplate<String,String> template = (RedisTemplate<String,String>)ctx.getBean("redisTemplate");BoundValueOperations<String,String> bounds=template.boundValueOps("aadasfda");bounds.set("aaavadfdlue");boolean success = bounds.persist();System.out.println(success);String value = bounds.get();System.out.println(value);BoundListOperations<String, String> listBounds = template.boundListOps("111");listBounds.rightPush("a");listBounds.rightPush("b");listBounds.rightPush("c");getListValues();}public static void getListValues(){ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-redis.xml");RedisTemplate<String,String> template = (RedisTemplate<String,String>)ctx.getBean("redisTemplate");BoundListOperations<String, String> listBounds = template.boundListOps("111");System.out.println(listBounds.size());System.out.println(listBounds.leftPop());}}
4.执行main函数输出:
2012-5-24 15:28:53 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc: startup date [Thu May 24 15:28:53 CST 2012]; root of context hierarchy2012-5-24 15:28:53 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [spring-redis.xml]2012-5-24 15:28:53 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1292d26: defining beans [jedisFactory,redisTemplate]; root of factory hierarchyfalseaaavadfdlue2012-5-24 15:28:53 org.springframework.context.support.AbstractApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ef137d: startup date [Thu May 24 15:28:53 CST 2012]; root of context hierarchy2012-5-24 15:28:53 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [spring-redis.xml]2012-5-24 15:28:53 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@cdb06e: defining beans [jedisFactory,redisTemplate]; root of factory hierarchy3a
有兴趣的可以再看下关于进一步源码框架相关的一篇http://zhwj184.iteye.com/blog/1539857
参考使用文档:
http://static.springsource.org/spring-data/redis/docs/current/reference/index.html
https://github.com/SpringSource/spring-data-redis
- spring-data spring 的nosql的orm框架学习
- spring-data spring 的nosql的orm框架设计学习
- Spring data jpa 和 ORM框架的关系
- spring data jpa、jpa以及ORM框架之间的关系
- JPA规范介绍以及JPA、ORM框架以及Spring Data Jpa的关系
- Morphia一个nosql的ORM框架
- ORM--------Hibernate、Mybatis与Spring Data的区别
- ORM--------Hibernate、Mybatis与Spring Data的区别
- ORM--------Hibernate、Mybatis与Spring Data的区别
- NoSQL的Spring
- NoSQL的Spring
- Spring框架的学习
- spring集成ORM框架
- Spring集成ORM框架之JDBC的使用
- Spring集成ORM框架之Hibernate的使用
- spring boot 框架处理spring data jpa的session
- Spring orm +Spring data jpa 入门
- Spring框架学习【Spring事务处理的实现】
- 穿过小楼飞鸽传书
- oracle/mysql TOP/Button N查询
- log4j MDC NDC应用场景
- 在EBS开发(form builder)中使用文件夹(folder)功能的步骤
- C++编译器处理成员函数和静态成员
- spring-data spring 的nosql的orm框架学习
- 一个大三学生的无奈
- spring-data spring 的nosql的orm框架设计学习
- Spring Data MongoDB hello world 示例
- LINUX samba的安装使用
- java 的svn客户端调用示例
- j2ee页面静态化方案encache web cache框架详解1
- 招商银行一卡通金卡与普卡的区别
- j2ee页面静态化方案encache web cache框架源码分析2