发表于: 2017-05-10 23:43:14

1 1092


今天完成的事:

1、重新找过一个redis的例子并配置运行

<?xml version="1.0" encoding="UTF-8"?>
<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"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd">
   <!--<bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
       <!--<property name="location" value="classpath:redis.properties"/>-->
   <!--</bean>-->

   <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig" >

       <property name="maxTotal" value="300" />
       <!--最大空闲连接数-->
       <property name="maxIdle" value="100" />
       <!--初始化连接数-->
       <property name="minIdle" value="50"/>
       <!--最大等待时间-->
       <property name="maxWaitMillis" value="80000" />
       <!--对拿到的connection进行validateObject校验-->
       <property name="testOnBorrow" value="false" />
       <!--在进行returnObject对返回的connection进行validateObject校验-->
       <property name="testOnReturn" value="false" />
       <!--定时对线程池中空闲的链接进行validateObject校验-->
       <property name="testWhileIdle" value="false" />
   </bean>
   <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
       <property name="hostName" value="127.0.0.1"/>
       <property name="port" value="6379"/>
       <!--<property name="password" value="${redis.pass}"/>-->
       <property name="poolConfig" ref="poolConfig"/>


   </bean>
         <!--p:host-name="${redis.host}"-->
         <!--p:port="${redis.port}"-->
         <!--p:password="${redis.pass}"-->
         <!--p:pool-config-ref="poolConfig"/>-->
   <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
       <constructor-arg index="0" ref="poolConfig"/>
       <constructor-arg index="1" value="127.0.0.1"/>
       <constructor-arg index="2" value="6379" type="int"/>
       <constructor-arg index="3" value="25000" type="int"/>
       <!--<constructor-arg index="4" value="${redis.pass}"/>-->
   </bean>
   <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
       <property name="connectionFactory" ref="connectionFactory" />

   </bean>
   <bean id="redisService" class="com.jnshu.util.RedisService"></bean>
</beans>
for (Integer id:intList){
System.out.println(redisService);
   if (redisService!=null&&redisService.exists(("student_"+id))){
student=(Student)serializeUtil.unserizlize(redisService.get(("student_"+id).getBytes()));
       studentList.add(student);
       System.out.println("从缓存中获取StudentID="+id);
   }else {
student=studentDao.getStudentById(id);
       if (redisService!=null){
redisService.set(("student_"+id).getBytes(),serializeUtil.serialize(student));
       }
System.out.println("从数据库中获取StudentID="+id);
       studentList.add(student);
   }
<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring-mybatis.xml,classpath:spring-redis.xml</param-value>
</context-param>

遇到的问题:

1、依然是,程序运行后(从缓存中获取数据),将redis的服务(进程)关闭后程序崩溃(不能达到预想中去数据库查数据的逻辑)

2、今天将代码贴好后出现异常,因为该异常前面显示的也是不能创建XXbean,和不能@autowrite xxbean刚开始以为是配置和注解弄错了,弄了很长时间,后听老大在群里讲解spring的context配置后再配置了下,才注意到下面的内容。网上查了下,说是jar包冲突的问题

下面的两个jar包版本是有适配关系的(这两个没问题,之前有问题的查看的时候撤销过了头,回不来了没截到图)

明天计划的事:向大佬请教我的redis问题,然后做任务7

收获:无

总结:又有点怀疑人生了


返回列表 返回列表
评论

    分享到