线上运行错误

提问 未结 0 158
layuiManage
悬赏:20积分
您好!请教个问题,我把shiro的session使用redis管理后线上打包运行报错了,而本地打的jar包丢到线上运行正常,错误如下图:img[//cdn.renren.io/c4778201905141413332847.png] ,shiroConfig改成了内部类 /** * Shiro的配置文件 * * @author Mark sunlightcs@gmail.com * @since 3.0.0 2017-09-27 */ @Configuration @ComponentScan("har.ocs") public class ShiroConfig { /** * 单机环境,session交给shiro管理 */ @Bean("sessionManager") @ConditionalOnProperty(prefix = "renren", name = "cluster", havingValue = "false") public DefaultWebSessionManager sessionManager(@Value("${ocs.globalSessionTimeout:3600}") long globalSessionTimeout){ DefaultWebSessionManager sessionManager = new DefaultWebSessionManager(); sessionManager.setSessionValidationSchedulerEnabled(true); sessionManager.setSessionIdUrlRewritingEnabled(false); sessionManager.setSessionValidationInterval(globalSessionTimeout * 1000); sessionManager.setGlobalSessionTimeout(globalSessionTimeout * 1000); return sessionManager; } /** * 集群环境,session交给spring-session管理 */ @Bean @ConditionalOnProperty(prefix = "renren", name = "cluster", havingValue = "true") public ServletContainerSessionManager servletContainerSessionManager() { return new ServletContainerSessionManager(); } @Bean("lifecycleBeanPostProcessor") public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } @Bean public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator(); proxyCreator.setProxyTargetClass(true); return proxyCreator; } @Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) { AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor(); advisor.setSecurityManager(securityManager); return advisor; } /** * 由于容器加载到bean redisCacheManager、redisSessionDAO 时bean redisService 还未被加载到容器中 * * 此时注入的bean redisService == null,使用内部内,在内部内中依赖 redisService bean,保证redisService bean * * 在此bean 之前被加载到容器中 */ @Configuration public static class SessionManager{ @Autowired private RedisService redisService; @Bean("securityManager") public SecurityManager securityManager(UserRealm userRealm, SessionManager sessionManager) { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(userRealm); securityManager.setRememberMeManager(null); // 自定义缓存实现 使用redis //securityManager.setCacheManager(onlineSessionManager.redisCacheManager()); // 自定义session管理 使用redis securityManager.setSessionManager(sessionManager()); return securityManager; } @Bean("shiroFilter") public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean(); shiroFilter.setSecurityManager(securityManager); shiroFilter.setLoginUrl("/login.html"); shiroFilter.setUnauthorizedUrl("/"); Map<String, String> filterMap = new LinkedHashMap<>(); filterMap.put("/swagger/**", "anon"); filterMap.put("/v2/api-docs", "anon"); filterMap.put("/swagger-ui.html", "anon"); filterMap.put("/webjars/**", "anon"); filterMap.put("/swagger-resources/**", "anon"); filterMap.put("/statics/**", "anon"); filterMap.put("/pub/**", "anon"); filterMap.put("/temp/**", "anon"); filterMap.put("/login.html", "anon"); filterMap.put("/sys/login", "anon"); filterMap.put("/favicon.ico", "anon"); filterMap.put("/captcha.jpg", "anon"); filterMap.put("/editor/**","anon"); filterMap.put("/kickout", "anon"); filterMap.put("/**", "kickout,user,authc"); //自定义拦截器 Map<String, Filter> filtersMap = new LinkedHashMap<String, Filter>(); //限制同一帐号同时在线的个数。 filtersMap.put("kickout", accessSessionControlFilter()); shiroFilter.setFilters(filtersMap); shiroFilter.setFilterChainDefinitionMap(filterMap); return shiroFilter; } /** * RedisSessionDAO shiro sessionDao层的实现 通过redis * 使用的是shiro-redis开源插件 */ @Bean(name = "redisSessionDAO") public RedisSessionDAO redisSessionDAO() { RedisSessionDAO redisSessionDAO = new RedisSessionDAO(); redisSessionDAO.setRedisManager(redisService.redisManager()); return redisSessionDAO; } /** * cacheManager 缓存 redis实现 * 使用的是shiro-redis开源插件@ComponentScan * @return */ @Bean(name = "redisCacheManager") public RedisCacheManager redisCacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(); redisCacheManager.setRedisManager(redisService.redisManager()); redisCacheManager.setKeyPrefix(Constants.SHIRO_REDIS_CACHE); return redisCacheManager; } /** * shiro session的管理 */ @Bean("onlineSessionManager") public DefaultWebSessionManager sessionManager() { DefaultWebSessionManager sessionManager = new DefaultWebSessionManager(); sessionManager.setSessionDAO(redisSessionDAO()); return sessionManager; } /** * 限制同一账号登录同时登录人数控制 * @return */ public AccessSessionControlFilter accessSessionControlFilter(){ AccessSessionControlFilter kickoutSessionControlFilter = new AccessSessionControlFilter(); //使用cacheManager获取相应的cache来缓存用户登录的会话;用于保存用户—会话之间的关系的; //这里我们还是用之前shiro使用的redisManager()实现的cacheManager()缓存管理 //也可以重新另写一个,重新配置缓存时间之类的自定义缓存属性 //kickoutSessionControlFilter.setCacheManager(redisCacheManager()); //用于根据会话ID,获取会话进行踢出操作的; kickoutSessionControlFilter.setSessionManager(sessionManager()); //是否踢出后来登录的,默认是false;即后者登录的用户踢出前者登录的用户;踢出顺序。 kickoutSessionControlFilter.setKickoutAfter(false); //同一个用户最大的会话数,默认5;比如5的意思是同一个用户允许最多同时五个人登录; // kickoutSessionControlFilter.setMaxSession(5); //被踢出后重定向到的地址; kickoutSessionControlFilter.setKickoutUrl("/login.html"); return kickoutSessionControlFilter; } } } 而且服务器上打的jar比本地打的jar稍微大一点,请指教下!!帮忙看看非常谢谢
回帖
  • 消灭零回复