[03] SpringBoot+MyBatis+Shiro搭建杂谈
0、写在前面的话
- zheng 基于Spring+SpringMVC+Mybatis分布式敏捷开发系统架构,提供整套公共微服务服务模块
- ES JavaEE企业级项目的快速开发的脚手架,提供了底层抽象和通用功能,拿来即用
- renren-security 轻量级权限管理系统
- lenos 快速开发模块化脚手架
1、技术框架整合
1.1 Maven多模块项目的搭建
1.2 SpringBoot-MyBatis集成
1.3 SpringBoot-Shiro集成
2、踩坑警告
- SpringBoot 版本:2.0.3.RELEASE
- JUnit 版本:4.12
- SpringBoot-MyBatis 版本:1.3.2
- SpringBoot-Shiro 版本:1.4.0-RC2
2.1 多模块带来的注意事项



2.2 SpringBoot+MyBatis与单元测试
@Repository
@Mapper
public interface RoleDao {
int deleteByPrimaryKey(Long id);
int insert(Role record);
int insertSelective(Role record);
Role selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Role record);
int updateByPrimaryKey(Role record);
Set<Role> findAll();
Set<Role> findByUserId(Long userId);
}
@Repository
@Mapper
public interface RoleDao {
int deleteByPrimaryKey(Long id);
int insert(Role record);
int insertSelective(Role record);
Role selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Role record);
int updateByPrimaryKey(Role record);
Set<Role> findAll();
Set<Role> findByUserId(Long userId);
}
2.3 Shiro中自定义Realm的Bean注册
@Configuration
public class ShiroConfig {
@Bean
public Realm realm() {
return new MyRealm();
}
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition() {
DefaultShiroFilterChainDefinition chain = new DefaultShiroFilterChainDefinition();
//todo "/anon" not useful
chain.addPathDefinition("/anon/*", "anon");
chain.addPathDefinition("/authc/*", "authc");
return chain;
}
}
x
@Configuration
public class ShiroConfig {
@Bean
public Realm realm() {
return new MyRealm();
}
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition() {
DefaultShiroFilterChainDefinition chain = new DefaultShiroFilterChainDefinition();
//todo "/anon" not useful
chain.addPathDefinition("/anon/*", "anon");
chain.addPathDefinition("/authc/*", "authc");
return chain;
}
}
//无需 @Component
public class MyRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//...
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//...
return null;
}
}
x
//无需 @Component
public class MyRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//...
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//...
return null;
}
}
- chain.addPathDefinition("/anon", "anon"); //无效
- chain.addPathDefinition("/anon/*", "anon"); //有效
3、Demo源码
[03] SpringBoot+MyBatis+Shiro搭建杂谈的更多相关文章
- springboot成神之——springboot+mybatis+mysql搭建项目简明demo
springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...
- SpringBoot+Mybatis集成搭建
本博客介绍一下SpringBoot集成Mybatis,数据库连接池使用alibaba的druid,使用SpringBoot微框架虽然集成Mybatis之后可以不使用xml的方式来写sql,但是用惯了x ...
- springboot+mybatis+shiro项目中使用shiro实现登录用户的权限验证。权限表、角色表、用户表。从不同的表中收集用户的权限、
要实现的目的:根据登录用户.查询出当前用户具有的所有权限.然后登录系统后.根据查询到的权限信息进行不同的操作. 以下的代码是在搭好的框架之下进行的编码. 文章目录 核心实现部分. 第一种是将用户表和角 ...
- springboot+mybatis+shiro——shiro简介
转载:[一]shiro入门 之 Shiro简介 一.shiro介绍: 官方网址:http://shiro.apache.org/introduction.html,shiro的功能包括:认证.授权.加 ...
- springboot+mybatis+shiro——登录认证和权限控制
转载:https://z77z.oschina.io/ 一.引入依赖 shiro-all包含shiro所有的包.shiro-core是核心包.shiro-web是与web整合.shiro-spring ...
- springboot + mybatis 前后端分离项目的搭建 适合在学习中的大学生
人生如戏,戏子多半掉泪! 我是一名大四学生,刚进入一家软件件公司实习,虽说在大学中做过好多个实训项目,都是自己完成,没有组员的配合.但是在这一个月的实习中,我从以前别人教走到了现在的自学,成长很多. ...
- Mysql8.0主从复制搭建,shardingsphere+springboot+mybatis读写分离
1.安装mysql8.0 首先需要在192.167.3.171上安装JDK. 下载mysql安装包,https://dev.mysql.com/downloads/,找到以下页面下载. 下载后放到li ...
- Shiro+springboot+mybatis(md5+salt+散列)认证与授权-01
这个小项目包含了注册与登录,使用了springboot+mybatis+shiro的技术栈:当用户在浏览器登录时发起请求时,首先这一系列的请求会被拦截器进行拦截(ShiroFilter),然后拦截器根 ...
- Shiro+springboot+mybatis+EhCache(md5+salt+散列)认证与授权-03
从上文:Shiro+springboot+mybatis(md5+salt+散列)认证与授权-02 当每次进行刷新时,都会从数据库重新查询数据进行授权操作,这样无疑给数据库造成很大的压力,所以需要引入 ...
随机推荐
- 苹果手机怎么屏幕录屏 ios10怎么录屏
手机录屏已经现阶段经常使用的功能,有些人喜欢在手机上看视频,看直播.但是有时候看到很精彩的视频,就想要录制下来,这个时候可以采取录屏的方式.那么就涉及到手机怎么录制屏幕视频了?想用苹果手机把手机屏幕录 ...
- Flutter 布局(一)- Container详解
本文主要介绍Flutter中非常常见的Container,列举了一些实际例子介绍如何使用. 1. 简介 A convenience widget that combines common painti ...
- vertical-align属性探究
在前端开发中我们经常需要将元素垂直居中对齐,我们很自然的想到使用vertical-align属性,但是使用后却发现有时候能起作用,有时候却又不起作用.究其原因还是因为我们没有将vertical-ali ...
- MySQL 约束、表连接、表关联、索引
一.外键: 1.什么是外键 2.外键语法 3.外键的条件 4.添加外键 5.删除外键 1.什么是外键: 主键:是唯一标识一条记录,不能有重复的,不允许为空,用来保证数据完整性. 外键:是另一表的唯一性 ...
- PHP 生成器语法
一般你在迭代一组数据的时候,需要创建一个数据,假设数组很大,则会消耗很大性能,甚至造成内存不足. //Fatal error: Allowed memory size of 1073741824 by ...
- ssh-keygen的学习总结
ssh-keygen介绍 维基百科上关于ssh-keygen的介绍如下: ssh-keygen is a standard component of the Secure Shell (S ...
- ueditor在线编辑器的简单使用-上传图片
由于我的项目个人博客网站需要用到在线编辑器,百度的ueditor编辑器就是一个很好的编辑器.开始比较迷茫的使用,各种百度,没有我满意的答案,明明可以很简单的使用. 1.首先进入ueditor官网下载, ...
- 两个Map的对比,三种方法,将对比结果写入文件。
三种方法的思维都是遍历一个map的Key,然后2个Map分别取这2个Key值所得到的Value. #第一种用entry private void compareMap(Map<String, S ...
- oracle USING 用法
提问 using(xx)中可以接多个列吗? using(xx)中的列可以接表名或别名吗? 在使用using的语句中,select * 可以使用吗? 如果表有别名t,select t.* from ta ...
- Turtle绘制带颜色和字体的图形(Python3)
转载自https://blog.csdn.net/wumenglu1018/article/details/78184930 在Python中有很多编写图形程序的方法,一个简单的启动图形化程序设计的方 ...