springboot+shiro使用ehcache热部署遇到的问题及解决

在coding中使用了devtools热启动,结果每次保存代码都会报错:

The source of the existing CacheManager is: InputStreamConfigurationSource [stream=java.io.BufferedInputStream@13ceee8c]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealm' defined in class path resource [cn/mirak/framework/config/ShiroConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [cn.mirak.framework.shiro.realm.UserRealm]: Factory method 'userRealm' threw exception; nested exception is org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Another CacheManager with same name 'em' already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.

Another CacheManager with same name 'em' already exists in the same VM

可知已存在一个名为em的CacheManager,遂百度,找到net.sf.ehcache.CacheManager的getCacheManager(Java.lang.String)方法可以按名称获取CacheManager ,但我用的是org.apache.shiro.cache.ehcache.EhCacheManage,不能直接转换类型.

于是看org.apache.shiro.cache.ehcache.EhCacheManager的源码,发现有这样个属性和这样个方法

    /**
     * The EhCache cache manager used by this implementation to create caches.
     */
    protected net.sf.ehcache.CacheManager manager;
    /**
     * Sets the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance.
     *
     * @param manager the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance.
     */
    public void setCacheManager(net.sf.ehcache.CacheManager manager) {
        this.manager = manager;
    }
原来最终用的还是 net.sf.ehcache.CacheManager,思路来了

代码如下

    @Bean
    public EhCacheManager getEhCacheManager()
    {
    	net.sf.ehcache.CacheManager cacheManager = net.sf.ehcache.CacheManager.getCacheManager("em");
    	EhCacheManager em = new EhCacheManager();
    	if(ObjectUtils.isEmpty(cacheManager)) {
            em.setCacheManagerConfigFile("classpath:ehcache/ehcache-shiro.xml");
            return em;
    	} else {
    		em.setCacheManager(cacheManager);
    		return em;
    	}
    }
再次保存,问题解决
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,由于篇幅和涉及版权等问题,无法提供完整的代码实现。以下是基于springboot+shiro+layui实现qq聊天室功能的代码结构和主要实现思路供参考: 1. 后端代码结构 - controller:控制层,实现用户登录、注册等接口。 - service:服务层,实现用户管理、聊天消息管理等业务逻辑。 - dao:数据访问层,实现对数据库的增删改查操作。 - entity:实体类,包括用户信息、聊天消息等。 - config:配置类,实现Shiro安全框架的配置。 - websocket:WebSocket实现,接收消息并广播给在线用户。 2. 前端代码结构 - index.html:聊天室主页面。 - login.html:用户登录页面。 - register.html:用户注册页面。 - layui:Layui框架相关文件。 - js:前端JS代码,实现聊天室界面和逻辑。 3. 主要实现思路 - 用户登录:前端发送用户名和密码到后台,后台进行密码验证并返回登录结果。 - 用户注册:前端发送用户名和密码到后台,后台将用户信息保存到数据库中。 - 聊天室界面:前端使用Layui实现聊天室界面,包括聊天消息显示和发送消息等功能。 - 实时通讯:使用WebSocket实现前后端实时通讯功能,后端接收消息并将消息广播给所有在线用户,前端接收消息并显示在聊天室界面中。 - 私聊功能:在聊天室界面中添加私聊功能,用户可以选择一个在线用户进行私聊,后端接收私聊消息并发送给对应的用户。 - 数据库存储:使用MySQL作为持久化存储,将用户信息、聊天记录等数据保存到数据库中。 以上是springboot+shiro+layui实现qq聊天室功能的主要实现思路和代码结构,具体实现过程需要根据实际需求进行调整和改进。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值