spring boot整合redis集成redis为什么报数据源装载失败

有没有哪位大神遇到过在spring boot下集成redis后,再集成shiro后,redis使用的@Cacheable注解不起作用了
[问题点数:20分,结帖人shijing266]
有没有哪位大神遇到过在spring boot下集成redis后,再集成shiro后,redis使用的@Cacheable注解不起作用了
[问题点数:20分,结帖人shijing266]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。76401人阅读
Redis(4)
&modelVersion&4.0.0&/modelVersion&
&groupId&com.x.redis&/groupId&
&artifactId&springredis&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&dependencies&
&dependency&
&groupId&org.springframework.data&/groupId&
&artifactId&spring-data-redis&/artifactId&
&version&1.0.2.RELEASE&/version&
&/dependency&
&dependency&
&groupId&org.springframework&/groupId&
&artifactId&spring-test&/artifactId&
&version&3.1.2.RELEASE&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&redis.clients&/groupId&
&artifactId&jedis&/artifactId&
&version&2.1.0&/version&
&/dependency&
&dependency&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.8.2&/version&
&scope&test&/scope&
&/dependency&
&/dependencies&
spring配置文件(applicationContext.xml):
&?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:context=&http://www.springframework.org/schema/context&
xmlns:jee=&http://www.springframework.org/schema/jee& xmlns:tx=&http://www.springframework.org/schema/tx&
xmlns:aop=&http://www.springframework.org/schema/aop&
xsi:schemaLocation=&
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd&&
&context:property-placeholder location=&classpath:redis.properties& /&
&bean id=&poolConfig& class=&redis.clients.jedis.JedisPoolConfig&&
&property name=&maxIdle& value=&${redis.maxIdle}& /&
&property name=&maxActive& value=&${redis.maxActive}& /&
&property name=&maxWait& value=&${redis.maxWait}& /&
&property name=&testOnBorrow& value=&${redis.testOnBorrow}& /&
&bean id=&connectionFactory& class=&org.springframework.data.redis.connection.jedis.JedisConnectionFactory&
p:host-name=&${redis.host}& p:port=&${redis.port}& p:password=&${redis.pass}&
p:pool-config-ref=&poolConfig&/&
&bean id=&redisTemplate& class=&org.springframework.data.redis.core.StringRedisTemplate&&
&property name=&connectionFactory&
ref=&connectionFactory& /&
&bean id=&userDao& class=&com.x.dao.impl.UserDao& /&
redis.properties
# Redis settings
redis.host=localhost
redis.port=6379
redis.pass=java2000_wl
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true
java代码:
package com.x.
import java.io.S
* @author http://blog.csdn.net/java2000_wl
* @version &b&1.0&/b&
public class User implements Serializable {
private static final long serialVersionUID = -0393952L;
* &br&------------------------------&br&
public User() {
* &br&------------------------------&br&
public User(String id, String name, String password) {
this.name =
this.password =
* @return the id
public String getId() {
* @param id the id to set
public void setId(String id) {
* 获得name
* @return the name
public String getName() {
* 设置name
* @param name the name to set
public void setName(String name) {
this.name =
* 获得password
* @return the password
public String getPassword() {
* 设置password
* @param password the password to set
public void setPassword(String password) {
this.password =
}package com.x.
import org.springframework.beans.factory.annotation.A
import org.springframework.data.redis.core.RedisT
import org.springframework.data.redis.serializer.RedisS
* AbstractBaseRedisDao
* @author http://blog.csdn.net/java2000_wl
* @version &b&1.0&/b&
public abstract class AbstractBaseRedisDao&K, V& {
@Autowired
protected RedisTemplate&K, V& redisT
* 设置redisTemplate
* @param redisTemplate the redisTemplate to set
public void setRedisTemplate(RedisTemplate&K, V& redisTemplate) {
this.redisTemplate = redisT
* 获取 RedisSerializer
* &br&------------------------------&br&
protected RedisSerializer&String& getRedisSerializer() {
return redisTemplate.getStringSerializer();
}package com.x.
import java.util.L
import com.x.entity.U
* @author http://blog.csdn.net/java2000_wl
* @version &b&1.0&/b&
public interface IUserDao {
* &br&------------------------------&br&
* @param user
boolean add(User user);
* 批量新增 使用pipeline方式
* &br&------------------------------&br&
* @param list
boolean add(List&User& list);
* &br&------------------------------&br&
* @param key
void delete(String key);
* 删除多个
* &br&------------------------------&br&
* @param keys
void delete(List&String& keys);
* &br&------------------------------&br&
* @param user
boolean update(User user);
* 通过key获取
* &br&------------------------------&br&
* @param keyId
User get(String keyId);
}package com.x.dao.
import java.util.ArrayL
import java.util.L
import org.springframework.dao.DataAccessE
import org.springframework.data.redis.connection.RedisC
import org.springframework.data.redis.core.RedisC
import org.springframework.data.redis.serializer.RedisS
import org.springframework.util.A
import com.x.dao.AbstractBaseRedisD
import com.x.dao.IUserD
import com.x.entity.U
* @author http://blog.csdn.net/java2000_wl
* @version &b&1.0&/b&
public class UserDao extends AbstractBaseRedisDao&String, User& implements IUserDao {
*&br&------------------------------&br&
* @param user
public boolean add(final User user) {
boolean result = redisTemplate.execute(new RedisCallback&Boolean&() {
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer&String& serializer = getRedisSerializer();
byte[] key
= serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
return connection.setNX(key, name);
* 批量新增 使用pipeline方式
*&br&------------------------------&br&
*@param list
public boolean add(final List&User& list) {
Assert.notEmpty(list);
boolean result = redisTemplate.execute(new RedisCallback&Boolean&() {
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer&String& serializer = getRedisSerializer();
for (User user : list) {
byte[] key
= serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
connection.setNX(key, name);
}, false, true);
* &br&------------------------------&br&
* @param key
public void delete(String key) {
List&String& list = new ArrayList&String&();
list.add(key);
delete(list);
* 删除多个
* &br&------------------------------&br&
* @param keys
public void delete(List&String& keys) {
redisTemplate.delete(keys);
* &br&------------------------------&br&
* @param user
public boolean update(final User user) {
String key = user.getId();
if (get(key) == null) {
throw new NullPointerException(&数据行不存在, key = & + key);
boolean result = redisTemplate.execute(new RedisCallback&Boolean&() {
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer&String& serializer = getRedisSerializer();
byte[] key
= serializer.serialize(user.getId());
byte[] name = serializer.serialize(user.getName());
connection.set(key, name);
* 通过key获取
* &br&------------------------------&br&
* @param keyId
public User get(final String keyId) {
User result = redisTemplate.execute(new RedisCallback&User&() {
public User doInRedis(RedisConnection connection)
throws DataAccessException {
RedisSerializer&String& serializer = getRedisSerializer();
byte[] key = serializer.serialize(keyId);
byte[] value = connection.get(key);
if (value == null) {
String name = serializer.deserialize(value);
return new User(keyId, name, null);
}import java.util.ArrayL
import java.util.L
import junit.framework.A
import org.junit.T
import org.springframework.beans.factory.annotation.A
import org.springframework.test.context.ContextC
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextT
import com.x.dao.IUserD
import com.x.entity.U
* @author http://blog.csdn.net/java2000_wl
* @version &b&1.0&/b&
@ContextConfiguration(locations = {&classpath*:applicationContext.xml&})
public class RedisTest extends AbstractJUnit4SpringContextTests {
@Autowired
private IUserDao userD
* &br&------------------------------&br&
public void testAddUser() {
User user = new User();
user.setId(&user1&);
user.setName(&java2000_wl&);
boolean result = userDao.add(user);
Assert.assertTrue(result);
* 批量新增 普通方式
* &br&------------------------------&br&
public void testAddUsers1() {
List&User& list = new ArrayList&User&();
for (int i = 10; i & 50000; i++) {
User user = new User();
user.setId(&user& + i);
user.setName(&java2000_wl& + i);
list.add(user);
long begin = System.currentTimeMillis();
for (User user : list) {
userDao.add(user);
System.out.println(System.currentTimeMillis() -
* 批量新增 pipeline方式
* &br&------------------------------&br&
public void testAddUsers2() {
List&User& list = new ArrayList&User&();
for (int i = 10; i & 1500000; i++) {
User user = new User();
user.setId(&user& + i);
user.setName(&java2000_wl& + i);
list.add(user);
long begin = System.currentTimeMillis();
boolean result = userDao.add(list);
System.out.println(System.currentTimeMillis() - begin);
Assert.assertTrue(result);
* &br&------------------------------&br&
public void testUpdate() {
User user = new User();
user.setId(&user1&);
user.setName(&new_password&);
boolean result = userDao.update(user);
Assert.assertTrue(result);
* 通过key删除单个
* &br&------------------------------&br&
public void testDelete() {
String key = &user1&;
userDao.delete(key);
* 批量删除
* &br&------------------------------&br&
public void testDeletes() {
List&String& list = new ArrayList&String&();
for (int i = 0; i & 10; i++) {
list.add(&user& + i);
userDao.delete(list);
* &br&------------------------------&br&
public void testGetUser() {
String id = &user1&;
User user = userDao.get(id);
Assert.assertNotNull(user);
Assert.assertEquals(user.getName(), &java2000_wl&);
* 设置userDao
* @param userDao the userDao to set
public void setUserDao(IUserDao userDao) {
this.userDao = userD
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:603644次
积分:6747
积分:6747
排名:第2085名
原创:81篇
转载:10篇
评论:290条
阅读:58636
阅读:8213
文章:11篇
阅读:126911
(2)(2)(1)(1)(1)(9)(4)(2)(7)(10)(4)(13)(6)(19)(4)(8)(1)(1)(4)Spring boot配合Spring session(redis)遇到的错误 - shihuc - 博客园
践行孤独之美
posts - 57, comments - 4, trackbacks - 0, articles - 0
背景:本MUEAS项目,一开始的时候,是没有引入redis的,考虑到后期性能的问题而引入。之前没有引用redis的时候,用户登录是正常的。但是,在加入redis支持后,登录就出错!错误如下:
/\\ / ___'_ __ _ _(_)_ __
__ _ \ \ \ \
3 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
___)| |_)| | | | | || (_| |
|____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::
(v1.2.7.RELEASE)
9 [2015-12-29 10:18:37.165] log4j - 31595
INFO [main] --- Application: Starting Application on CloudGame with PID 31595 (/home/webWps/mueas-mongo/target/classes started by root in /home/webWps/mueas-mongo)
10 [2015-12-29 10:18:37.237] log4j - 31595
INFO [main] --- AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7c271d34: startup date [Tue Dec 29 10:18:37 CST 2015]; root of context hierarchy
11 [2015-12-29 10:18:39.868] log4j - 31595
INFO [main] --- AutowiredAnnotationBeanPostProcessor: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
12 [2015-12-29 10:18:40.163] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
13 [2015-12-29 10:18:40.419] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$525eef57] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
14 [2015-12-29 10:18:40.449] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
15 [2015-12-29 10:18:40.451] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@2cd84149' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
16 [2015-12-29 10:18:40.476] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'mueasPermissionEvaluator' of type [class com.tinguish.mueas.infra.security.MueasPermissionEvaluator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17 [2015-12-29 10:18:40.540] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'methodSecurityConfig' of type [class com.tinguish.mueas.infra.security.MethodSecurityConfig$$EnhancerBySpringCGLIB$$5242b1ec] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
18 [2015-12-29 10:18:40.557] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
19 [2015-12-29 10:18:40.562] log4j - 31595
INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'metaDataSourceAdvisor' of type [class org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
20 [2015-12-29 10:18:41.039] log4j - 31595
INFO [main] --- TomcatEmbeddedServletContainer: Tomcat initialized with port(s): 8080 (http)
21 [2015-12-29 10:18:41.449] log4j - 31595
INFO [main] --- StandardService: Starting service Tomcat
22 [2015-12-29 10:18:41.451] log4j - 31595
INFO [main] --- StandardEngine: Starting Servlet Engine: Apache Tomcat/8.0.28
23 [2015-12-29 10:18:41.657] log4j - 31595
INFO [localhost-startStop-1] --- [/]: Initializing Spring embedded WebApplicationContext
24 [2015-12-29 10:18:41.657] log4j - 31595
INFO [localhost-startStop-1] --- ContextLoader: Root WebApplicationContext: initialization completed in 4423 ms
25 [2015-12-29 10:18:44.031] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/css/**'], []
26 [2015-12-29 10:18:44.031] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/js/**'], []
27 [2015-12-29 10:18:44.031] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/images/**'], []
28 [2015-12-29 10:18:44.031] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/**/favicon.ico'], []
29 [2015-12-29 10:18:44.031] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: Ant [pattern='/error'], []
30 [2015-12-29 10:18:44.138] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@272b811d, org.springframework.security.web.context.SecurityContextPersistenceFilter@1ab55f98, org.springframework.security.web.header.HeaderWriterFilter@7da7fe14, org.springframework.security.web.authentication.logout.LogoutFilter@, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@55ac5e8a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@28facd93, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@74f4c543, org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter@4031202, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@1929ab02, org.springframework.security.web.session.SessionManagementFilter@615a1d5f, org.springframework.security.web.access.ExceptionTranslationFilter@1468193e, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@273c59de]
31 [2015-12-29 10:18:44.155] log4j - 31595
INFO [localhost-startStop-1] --- DefaultSecurityFilterChain: Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/**']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5f8f81db, org.springframework.security.web.context.SecurityContextPersistenceFilter@, org.springframework.security.web.header.HeaderWriterFilter@723a02aa, org.springframework.security.web.authentication.logout.LogoutFilter@60c20fb6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@6495a75a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@4acbe549, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@103a41fc, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@, org.springframework.security.web.session.SessionManagementFilter@3e85217c, org.springframework.security.web.access.ExceptionTranslationFilter@45c69c37, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3470e41a]
32 [2015-12-29 10:18:44.471] log4j - 31595
INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'characterEncodingFilter' to: [/*]
33 [ 10:18:44.471] log4j - 31595
INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
34 [ 10:18:44.472] log4j - 31595
INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'springSessionRepositoryFilter' to: [/*]
35 [ 10:18:44.472] log4j - 31595
INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'springSecurityFilterChain' to: [/*]
36 [ 10:18:44.472] log4j - 31595
INFO [localhost-startStop-1] --- ServletRegistrationBean: Mapping servlet: 'dispatcherServlet' to [/]
37 [ 10:18:44.838] log4j - 31595
INFO [main] --- RequestMappingHandlerAdapter: Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7c271d34: startup date [Tue Dec 29 10:18:37 CST 2015]; root of context hierarchy
38 [ 10:18:44.926] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/userid],methods=[POST]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userId(com.tinguish.mueas.user.model.User,java.lang.String)
39 [ 10:18:44.926] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/pri_college]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userPriCollege(com.tinguish.mueas.user.model.User)
40 [ 10:18:44.927] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/sec_college]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userSecCollege(com.tinguish.mueas.user.model.User)
41 [ 10:18:44.927] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/check/oldPassword]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.checkOldPassword(com.tinguish.mueas.user.model.User,java.lang.String)
42 [ 10:18:44.927] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.mySetting(com.tinguish.mueas.user.model.User)
43 [ 10:18:44.927] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_single]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.createSingleUser()
44 [ 10:18:44.927] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_multi]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.createMultiUsers()
45 [ 10:18:44.928] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/m_mgmt]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.user.controller.UserController.mgmtUsers(com.tinguish.mueas.user.model.User)
46 [ 10:18:44.928] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/new/one]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.createUser(javax.servlet.http.HttpServletRequest)
47 [ 10:18:44.928] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/profile]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userProfile(com.tinguish.mueas.user.model.User)
48 [ 10:18:44.928] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/username],methods=[POST]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userName(com.tinguish.mueas.user.model.User,java.lang.String)
49 [ 10:18:44.929] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/user/setting/password]}" onto public java.util.Map&java.lang.String, java.lang.String& com.tinguish.mueas.user.controller.UserController.userPassword(com.tinguish.mueas.user.model.User,java.lang.String,java.lang.String)
50 [ 10:18:44.929] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/ || /home]}" onto public java.lang.String com.tinguish.mueas.infra.login.LoginController.home()
51 [ 10:18:44.930] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/seeu]}" onto public java.lang.String com.tinguish.mueas.infra.login.LoginController.logout()
52 [ 10:18:44.930] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/login]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.infra.login.LoginController.login(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
53 [ 10:18:44.931] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/forgot],methods=[POST]}" onto public java.lang.String com.tinguish.mueas.infra.password.ForgotPasswordController.forgetPassword(com.tinguish.mueas.user.model.User,org.springframework.ui.Model) throws javax.mail.MessagingException,java.io.IOException
54 [ 10:18:44.931] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/forgot],methods=[GET]}" onto public java.lang.String com.tinguish.mueas.infra.password.ForgotPasswordController.resetPasswordView(org.springframework.ui.Model)
55 [ 10:18:44.932] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/reset],methods=[GET]}" onto public java.lang.String com.tinguish.mueas.infra.password.ResetPasswordController.resetpasswordView(java.lang.String,org.springframework.ui.Model)
56 [ 10:18:44.932] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/password/reset],methods=[POST]}" onto public java.lang.String com.tinguish.mueas.infra.password.ResetPasswordController.resetPassword(java.lang.String,com.tinguish.mueas.user.model.User,org.springframework.ui.Model)
57 [ 10:18:44.932] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/error]}" onto org.springframework.web.servlet.ModelAndView com.tinguish.mueas.infra.error.MueasErrorController.error(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
58 [ 10:18:44.933] log4j - 31595
INFO [main] --- RequestMappingHandlerMapping: Mapped "{[/mgmt/score/ || /mgmt/score]}" onto public org.springframework.web.servlet.ModelAndView com.tinguish.mueas.score.ScoreMgmtController.Score()
59 [ 10:18:44.992] log4j - 31595
INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
60 [ 10:18:44.993] log4j - 31595
INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
61 [ 10:18:45.090] log4j - 31595
INFO [main] --- SimpleUrlHandlerMapping: Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
62 [2015-12-29 10:18:45.544] log4j - 31595
INFO [main] --- AnnotationMBeanExporter: Registering beans for JMX exposure on startup
63 [2015-12-29 10:18:45.554] log4j - 31595
INFO [main] --- DefaultLifecycleProcessor: Starting beans in phase
64 [2015-12-29 10:18:45.757] log4j - 31595
INFO [main] --- TomcatEmbeddedServletContainer: Tomcat started on port(s): 8080 (http)
65 [2015-12-29 10:18:45.760] log4j - 31595
INFO [main] --- Application: Started Application in 8.99 seconds (JVM running for 9.316)
66 [2015-12-29 10:21:41.487] log4j - 31595
INFO [http-nio-8080-exec-1] --- [/]: Initializing Spring FrameworkServlet 'dispatcherServlet'
67 [2015-12-29 10:21:41.488] log4j - 31595
INFO [http-nio-8080-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization started
68 [2015-12-29 10:21:41.507] log4j - 31595
INFO [http-nio-8080-exec-1] --- DispatcherServlet: FrameworkServlet 'dispatcherServlet': initialization completed in 19 ms
69 [2015-12-29 10:21:41.690] log4j - 31595
INFO [http-nio-8080-exec-2] --- TemplateEngine: [THYMELEAF] INITIALIZING TEMPLATE ENGINE
70 [2015-12-29 10:21:41.765] log4j - 31595
INFO [http-nio-8080-exec-2] --- AbstractTemplateResolver: [THYMELEAF] INITIALIZING TEMPLATE RESOLVER: org.thymeleaf.templateresolver.TemplateResolver
71 [2015-12-29 10:21:41.765] log4j - 31595
INFO [http-nio-8080-exec-2] --- AbstractTemplateResolver: [THYMELEAF] TEMPLATE RESOLVER INITIALIZED OK
72 [2015-12-29 10:21:41.766] log4j - 31595
INFO [http-nio-8080-exec-2] --- AbstractMessageResolver: [THYMELEAF] INITIALIZING MESSAGE RESOLVER: org.thymeleaf.spring4.messageresolver.SpringMessageResolver
73 [2015-12-29 10:21:41.766] log4j - 31595
INFO [http-nio-8080-exec-2] --- AbstractMessageResolver: [THYMELEAF] MESSAGE RESOLVER INITIALIZED OK
74 [2015-12-29 10:21:41.775] log4j - 31595
INFO [http-nio-8080-exec-2] --- CONFIG: [THYMELEAF] TEMPLATE ENGINE CONFIGURATION:
75 [THYMELEAF] * Cache Factory implementation: org.thymeleaf.cache.StandardCacheManager
76 [THYMELEAF] * Template modes:
77 [THYMELEAF]
* VALIDXML
78 [THYMELEAF]
79 [THYMELEAF]
* VALIDXHTML
80 [THYMELEAF]
* LEGACYHTML5
81 [THYMELEAF]
82 [THYMELEAF]
83 [THYMELEAF] * Template resolvers (in order):
84 [THYMELEAF]
* org.thymeleaf.templateresolver.TemplateResolver
85 [THYMELEAF] * Message resolvers (in order):
86 [THYMELEAF]
* org.thymeleaf.spring4.messageresolver.SpringMessageResolver
87 [THYMELEAF] * Dialect [1 of 3]: org.thymeleaf.spring4.dialect.SpringStandardDialect
88 [THYMELEAF]
* Prefix: "th"
89 [THYMELEAF] * Dialect [2 of 3]: org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect
90 [THYMELEAF]
* Prefix: "sec"
91 [THYMELEAF] * Dialect [3 of 3]: nz.net.ultraq.thymeleaf.LayoutDialect
92 [THYMELEAF]
* Prefix: "layout"
93 [THYMELEAF] TEMPLATE ENGINE CONFIGURED OK
94 [2015-12-29 10:21:41.775] log4j - 31595
INFO [http-nio-8080-exec-2] --- TemplateEngine: [THYMELEAF] TEMPLATE ENGINE INITIALIZED
95 [2015-12-29 10:21:50.834] log4j - 31595 ERROR [http-nio-8080-exec-10] --- [dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
96 org.springframework.data.redis.serializer.SerializationException: C nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultS nested exception is java.io.NotSerializableException: com.tinguish.mueas.user.model.User
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:52)
at org.springframework.data.redis.core.AbstractOperations.rawHashValue(AbstractOperations.java:146)
at org.springframework.data.redis.core.DefaultHashOperations.putAll(DefaultHashOperations.java:128)
at org.springframework.data.redis.core.DefaultBoundHashOperations.putAll(DefaultBoundHashOperations.java:85)
at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.saveDelta(RedisOperationsSessionRepository.java:409)
at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.access$000(RedisOperationsSessionRepository.java:331)
at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:211)
at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:141)
at org.springframework.session.web.http.mitSession(SessionRepositoryFilter.java:193)
at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.access$100(SessionRepositoryFilter.java:169)
at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:127)
at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
134 Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultS nested exception is java.io.NotSerializableException: com.tinguish.mueas.user.model.User
at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:68)
at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:35)
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:50)
... 36 more
139 Caused by: java.io.NotSerializableException: com.tinguish.mueas.user.model.User
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at org.springframework.core.serializer.DefaultSerializer.serialize(DefaultSerializer.java:46)
at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:63)
... 38 more
很是奇怪。。。。。。
后来拜读了一下spring data redis的官方文档:
From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather then what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the RedisSerializer interface (package org.springframework.data.redis.serializer) which as the name implies, takes care of the serialization process. Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the StringRedisSerializer and the JdkSerializationRedisSerializer. However one can use OxmSerializer for Object/XML mapping through Spring 3
support or either JacksonJsonRedisSerializer, Jackson2JsonRedisSerializer or `GenericJackson2JsonRedisSerializer for storing data in
format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions.
从中得到一点启发,那就是spring session redis将session存入到redis后,是将数据序列化后存入的,所以,当没有序列化的数据,直接从数据库读出来,在经过spring security认证之后,会将SecurityContext写入到httpSesson中.
org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper中saveContext的操作,将会把SecurityContext以SPRING_SECURITY_CONTEXT为key写入httpSession中,而SecurityContext中包含了authentication (UsernamePasswordAuthenticationToken),这个,我相信大家都知道了,这个里面就含有当前登录操作的principle,即继承于UserDetails。
出于这个考虑,结合错误提示信息Caused by: java.io.NotSerializableException: com.tinguish.mueas.user.model.User,于是将我的User类,改为下面的形式:
1 //注意,我的User继承BasicUser,所以,只将BasicUser继承Serializable。
2 public class BasicUser implements Serializable{
private static final long serialVersionUID = -4774130L;
。。。。。。。。。。。。。
经过上面的简单修改后,果然,可以正常的登录了,不再出现上述错误,一切操作都正常!
正常运行下的redis的session下的内容可以看到:
127.0.0.1:6379& hkeys spring:session:sessions:f5a6f5fa-0d8a-4250-87bd-ca6a82384fe21) "sessionAttr:SPRING_SECURITY_SAVED_REQUEST"2) "sessionAttr:SPRING_SECURITY_CONTEXT"3) "maxInactiveInterval"4) "creationTime"5) "lastAccessedTime"6) "sessionAttr:SPRING_SECURITY_LAST_EXCEPTION"

我要回帖

更多关于 spring boot配置redis 的文章

 

随机推荐