springboot中shiro控制

来源:互联网 发布:时间提示软件 编辑:程序博客网 时间:2024/06/17 04:12
<body><div id="BAIDU_DUP_fp_wrapper" style="position: absolute; left: -1px; bottom: -1px; z-index: 0; width: 0px; height: 0px; overflow: hidden; visibility: hidden; display: none;"><iframe id="BAIDU_DUP_fp_iframe" src="https://pos.baidu.com/wh/o.htm?ltr=" style="width: 0px; height: 0px; visibility: hidden; display: none;"></iframe></div><div id="MathJax_Message" style="display: none;"></div><iframe frameborder="0" style="display: none;"></iframe><div class="csdn-toolbar csdn-toolbar-skin-black ">        <div class="container row center-block ">          <div class="col-md-3 pull-left logo clearfix"><a href="http://www.csdn.net?ref=toolbar" title="CSDN首页" target="_blank" class="icon"></a><a title="频道首页" href="http://blog.csdn.net?ref=toolbar_logo" class="img blog-icon"></a></div>          <div class="pull-right login-wrap ">            <ul class="btns">              <li class="loginlink"><a href="https://passport.csdn.net/account/login?ref=toolbar" target="_top">登录&nbsp;</a>|<a target="_top" href="http://passport.csdn.net/account/mobileregister?ref=toolbar&amp;action=mobileRegister">&nbsp;注册</a></li>              <li class="search">                <div class="icon on-search-icon">                  <div class="wrap">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                    <form action="http://so.csdn.net/search" id="toolbar_search" method="get" target="_blank">                      <input type="hidden" value="toolbar" name="ref" accesskey="2">                      <div class="border">                        <input placeholder="搜索" type="text" value="" name="q" accesskey="2"><span class="icon-enter-sm"></span>                      </div>                    </form>                  </div>                </div>              </li>              <li class="favor">                <div class="icon on-favor-icon">                  <div class="wrap">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                    <div style="display:none;" class="favor-success"><span class="msg">收藏成功</span>                      <div class="btns"><span class="btn btn-primary ok">确定</span></div>                    </div>                    <div style="display:none;" class="favor-failed"><span class="icon-danger-lg"></span><span class="msg">收藏失败,请重新收藏</span>                      <div class="btns"><span class="btn btn-primary ok">确定</span></div>                    </div>                    <form role="form" class="form-horizontal favor-form">                      <div class="form-group">                        <div class="clearfix">                          <label for="input-title" class="col-sm-2 control-label"><span class="red_txt">*</span>标题</label>                          <div class="col-sm-10">                            <input id="inputTitle" type="text" placeholder="" class="title form-control">                          </div>                        </div>                        <div class="alert alert-danger"><strong></strong>标题不能为空</div>                      </div>                      <div class="form-group" style="display:none;">                        <label for="input-url" class="col-sm-2 control-label">网址</label>                        <div class="col-sm-10">                          <input id="input-url" type="text" placeholder="" class="url form-control">                        </div>                      </div>                      <div class="form-group">                        <label for="input-tag" class="col-sm-2 tag control-label">标签</label>                        <div class="col-sm-10">                          <input id="input-tag" type="text" class="form-control tag">                        </div>                      </div>                      <div class="form-group">                        <label for="input-description" class="description col-sm-2 control-label">位置</label>                        <div class="col-sm-10">                          <div class="my_lib_box">                            个人主页&nbsp;-&nbsp;<a href="http://my.csdn.net/" target="_blank">我的知识</a>                          </div>                          <div class="checkbox">                            <div class="pull-left">                              <label>                                <input type="checkbox" name="share" class="save_lib_map" checked="checked">同时保存至:                              </label>                            </div>                            <div class="pull-left">                              <div class="dropdown">                                <button id="toolbar_sele_map" type="button">                                  选择知识图谱                                  <i class="fa fa-chevron-down"></i>                                </button>                                <div class="top_arr"></div>                                <div class="outside">                                  <ul class="dropdown-menu" id="toolbar_Design_knowledge"><li>选择知识图谱</li></ul>                                </div>                              </div>                            </div>                            <div class="pull-left new_txt">                              <a href="http://lib.csdn.net/my/create/structure" target="_blank">新建?</a>                            </div>                          </div>                        </div>                      </div>                      <div class="form-group">                        <div class="col-sm-offset-2 col-sm-10 ft">                          <div class="col-sm-4 pull-left" style="display:none">                            <div class="checkbox">                              <label>                                <input type="checkbox" name="share" checked="checked" class="share">公开                              </label>                            </div>                          </div>                          <div class="col-sm-8 pull-right favor-btns">                            <button type="button" class="cancel btn btn-default">取消</button>                            <button type="submit" class="submit btn btn-primary">收藏</button>                          </div>                        </div>                      </div>                    </form>                  </div>                </div>              </li>              <li class="notify">                <div style="display:none" class="number"></div>                <div style="" class="icon-hasnotes-sm"></div>                <div id="header_notice_num"><div class="icon-hasnotes" style=""></div></div>                <div class="icon on-notify-icon">                  <div class="wrap">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                    <div id="note1" class="csdn_note" style="left: -212px; top: 25px; display: none;">                      <div class="box"><div class="notifications notice_list_con curr">  <div class="menu_title">    <span class="title"><a href="http://msg.csdn.net/letters" target="_blank" class="read_all">查看所有私信</a><a href="http://msg.csdn.net" target="_blank" class="go_all">查看所有通知</a></span>  </div>  <div class="loading"></div>  <div class="empty">暂没有新通知</div>  <div class="notice_content"></div></div><div class="notifications detail_con" style="display: none">  <div class="menu_title">    <span class="title">      <a class="go_back" href="javascript:void 0;">返回通知列表</a>      <a class="notifications_page_none nextnote" href="javascript:void 0;">下一条</a>      <a class="notifications_page prvnote" href="javascript:void 0;">上一条</a>    </span>  </div>  <div class="notice_content" style="overflow-y: scroll; height: 250px;"></div></div><div class="error"></div></div>                    <iframe src="about:block" frameborder="0" allowtransparency="true" style="z-index:-1;position:absolute;top:0;left:0;width:100%;height:100%;background:transparent"></iframe></div>                  </div>                </div>              </li>              <li class="ugc">                <div class="icon on-ugc-icon">                  <div class="wrap clearfix">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                    <dl>                      <dt><a href="http://geek.csdn.net/news/expert?ref=toolbar" target="_blank" class="p-news clearfix" style="display:none;"><em class="icon"></em><span>分享资讯</span></a></dt>                      <dt style="border: none;"><a href="http://u.download.csdn.net/upload?ref=toolbar" target="_blank" class="p-doc clearfix"><em class="icon"></em><span>传PPT/文档</span></a></dt>                      <dt><a href="http://bbs.csdn.net/topics/new?ref=toolbar" target="_blank" class="p-ask clearfix"><em class="icon"></em><span>提问题</span></a></dt>                      <dt><a href="http://write.blog.csdn.net/postedit?ref=toolbar" target="_blank" class="p-blog clearfix"><em class="icon"></em><span>写博客</span></a></dt>                      <dt><a href="http://gitbook.cn/new/gitchat/activity?utm_source=csdnblog1" target="_blank" class="gitchat clearfix"><em class="icon"></em><span>发布Chat</span></a></dt>                      <dt><a href="http://u.download.csdn.net/upload?ref=toolbar" target="_blank" class="p-src clearfix"><em class="icon"></em><span>传资源</span></a></dt>                      <dt><a href="https://code.csdn.net/projects/new?ref=toolbar" target="_blank" class="c-obj clearfix"><em class="icon"></em><span>创建项目</span></a></dt>                      <dt><a href="https://code.csdn.net/snippets/new?ref=toolbar" target="_blank" class="c-code clearfix"><em class="icon"></em><span>创建代码片</span></a></dt>                    </dl>                  </div>                </div>              </li>              <li class="profile">                <div class="icon on-profile-icon"><img src="http://avatar.csdn.net/6/A/E/2_pingchangxin2017.jpg" class="curr-icon-img">                  <div class="wrap clearfix">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                    <div class="bd">                      <dl class="clearfix">                        <dt class="pull-left img"><a target="_blank" href="http://my.csdn.net?ref=toolbar" class="avatar"><img src="http://avatar.csdn.net/6/A/E/2_pingchangxin2017.jpg"></a></dt>                        <dd class="info" style="border: none;"><a target="_blank" href="http://my.csdn.net?ref=toolbar" class="nickname">pingchangxin2017</a><span class="dec"><a class="fill-dec" href="//my.csdn.net" target="_blank">编辑自我介绍,让更多人了解你<span class="write-icon"></span></a></span></dd>                      </dl>                    </div>                    <div class="ft clearfix"><a target="_blank" href="http://my.csdn.net/my/account/changepwd?ref=toolbar" class="pull-left"><span class="icon-cog"></span>帐号设置</a><a href="https://passport.csdn.net/account/logout?ref=toolbar" target="_top" class="pull-left" style="margin-left:132px; width:18px; height:27px; white-space:nowrap; overflow:hidden;"><span class="icon-signout"></span><span class="out">退出</span></a></div>                  </div>                </div>              </li>              <li class="apps">                <div id="chasnew123" class="hasnew" style="display: none;"></div>                <div id="cappsarea123" class="icon on-apps-icon">                  <div class="wrap clearfix">                    <div class="curr-icon-wrap">                      <div class="curr-icon"></div>                    </div>                  <div class="detail">                    <dl>                      <dt>                        <h5>社区</h5>                      </dt>                      <dd> <a href="http://blog.csdn.net?ref=toolbar" target="_blank">博客</a></dd>                      <dd> <a href="http://bbs.csdn.net?ref=toolbar" target="_blank">论坛</a></dd>                      <dd> <a href="http://download.csdn.net?ref=toolbar" target="_blank">下载</a></dd>                      <dd> <a href="http://lib.csdn.net?ref=toolbar" target="_blank">知识库</a></dd>                      <dd><a href="http://ask.csdn.net?ref=toolbar" target="_blank">技术问答</a></dd>                      <dd><a href="http://geek.csdn.net?ref=toolbar" target="_blank">极客头条</a></dd>                      <dd style="display:none"> <a href="http://hero.csdn.net?ref=toolbar" target="_blank">英雄会</a></dd>                    </dl>                  </div>                  <div class="detail">                    <dl>                      <dt>                        <h5>服务</h5>                      </dt>                      <dd style="display:none"> <a href="http://job.csdn.net?ref=toolbar" target="_blank">JOB<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>                      <dd> <a href="http://edu.csdn.net?ref=toolbar" target="_blank">学院<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>                      <dd> <a href="https://code.csdn.net?ref=toolbar" target="_blank">CODE</a></dd>                      <dd> <a href="http://huiyi.csdn.net/?ref=toolbar" target="_blank">活动</a></dd>                      <dd> <a href="http://www.csto.com?ref=toolbar" target="_blank">CSTO</a></dd>                      <dd> <a href="http://mall.csdn.net?ref=toolbar" target="_blank">C币兑换<img src="http://c.csdnimg.cn/public/common/toolbar/images/new.gif" style="display: none; margin-top: -26px; width: 23px;"></a></dd>                    </dl>                  </div>                  <div class="detail last">                    <dl>                      <dt>                        <h5>俱乐部</h5>                      </dt>                      <dd> <a href="http://cto.csdn.net?ref=toolbar" target="_blank">CTO俱乐部</a></dd>                      <dd> <a href="http://student.csdn.net?ref=toolbar" target="_blank">高校俱乐部</a></dd>                    </dl>                  </div>                </div>              </div>            </li>            </ul>          </div>        </div>    </div>
     


    <!-- 广告位开始 -->
        
    <!-- 广告位结束 -->


    
   
      <!--new top-->
    <script id="toolbar-tpl-scriptId" fixed="true" prod="blog" skin="black" src="http://c.csdnimg.cn/public/common/toolbar/js/html.js" type="text/javascript"></script>
     <!--new top-->
    <div id="container">
        <div id="header">
    <div class="header">
        <div id="blog_title">
            <h2>
                <a href="http://blog.csdn.net/catoop">小单的博客专栏</a></h2>
            <h3></h3>
            <div class="clear">
            </div>
        </div>
        <div class="clear">
        </div>
        
     
    </div>
</div>
<div id="navigator">
    <div class="navigator_bg">
    </div>
    <div class="navigator">
        <ul>           
                <li id="btnContents"><a href="http://blog.csdn.net/catoop?viewmode=contents"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_mulu'])">
                    <img src="http://static.blog.csdn.net/images/ico_list.gif">目录视图</span></a></li>
                <li id="btnView"><a href="http://blog.csdn.net/catoop?viewmode=list"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_zhaiyao'])">
                    <img src="http://static.blog.csdn.net/images/ico_summary.gif">摘要视图</span></a></li>
                <li id="btnRss"><a href="http://blog.csdn.net/catoop/rss/list"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_RSS'])">
                    <img src="http://static.blog.csdn.net/images/ico_rss.gif">订阅</span></a></li>                   
            


            </ul>
    </div>
</div>
<script type="text/javascript">
    var username = "catoop";
    var _blogger = username;
    var blog_address = "http://blog.csdn.net/catoop";
    var static_host = "http://static.blog.csdn.net";
    var currentUserName = "pingchangxin2017";  
</script>


        <div id="body">
            <div id="main">
                <div class="main">
                        <div class="ad_class">
<div class="notice tracking-ad" data-mod="popu_3"> 


<a href="http://blog.csdn.net/turingbooks/article/details/78475571" target="_blank">
<font color="red"><strong>图灵赠书——程序员11月书单</strong></font></a>


&nbsp;&nbsp;&nbsp;&nbsp;




<a href="http://edu.csdn.net/topic/python2?utm_source=blog4" target="_blank">
<font color="blue"><strong>【思考】Python这么厉害的原因竟然是!</strong></font></a>
&nbsp;&nbsp;&nbsp;&nbsp;


<a href="http://blog.csdn.net/epubit17/article/details/78606519" target="_blank">
<font color="blue"><strong>感恩节赠书:《深度学习》等异步社区优秀图书和作译者评选启动!</strong></font></a>


&nbsp;&nbsp;&nbsp;&nbsp;




<a href="http://blog.csdn.net/broadview2006/article/details/78603363" target="_blank">
<font color="red"><strong>每周荐书:京东架构、Linux内核、Python全栈</strong></font></a>






</div>                        </div>


                        






  












<script type="text/javascript" src="http://static.blog.csdn.net/scripts/category.js"></script>


  <script type="text/ecmascript">
      window.quickReplyflag = true;
      var isBole = false; 
      var fasrc="http://my.csdn.net/my/favorite/miniadd?t=Spring+Boot+Shiro+%e6%9d%83%e9%99%90%e7%ae%a1%e7%90%86&u=http://blog.csdn.net/catoop/article/details/50520958"
    </script>
<div id="article_details" class="details">
    <div class="article_title">   
         <span class="ico ico_type_Original"></span>


    <h1>
        <span class="link_title"><a href="/catoop/article/details/50520958">
        Spring Boot Shiro 权限管理        
           
        </a>
        </span>


         
    </h1>
</div>


   


        <div class="article_manage clearfix">
        <div class="article_l">
            <span class="link_categories">
            标签:
              <a href="http://www.csdn.net/tag/spring" target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">spring</a><a href="http://www.csdn.net/tag/shiro" target="_blank" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_tag']);">shiro</a>
            </span>
        </div>
        <div class="article_r">
            <span class="link_postdate">2016-01-14 23:44</span>
            <span class="link_view" title="阅读次数">84317人阅读</span>
            <span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(59)</span>
            <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('Spring+Boot+Shiro+%e6%9d%83%e9%99%90%e7%ae%a1%e7%90%86','50520958');return false;" title="收藏" target="_blank">收藏</a></span>
             <span class="link_report"> <a href="#report" onclick="javascript:report(50520958,2);return false;" title="举报">举报</a></span>


        </div>
    </div>    <style type="text/css">        
            .embody{
                padding:10px 10px 10px;
                margin:0 -20px;
                border-bottom:solid 1px #ededed;                
            }
            .embody_b{
                margin:0 ;
                padding:10px 0;
            }
            .embody .embody_t,.embody .embody_c{
                display: inline-block;
                margin-right:10px;
            }
            .embody_t{
                font-size: 12px;
                color:#999;
            }
            .embody_c{
                font-size: 12px;
            }
            .embody_c img,.embody_c em{
                display: inline-block;
                vertical-align: middle;               
            }
             .embody_c img{               
                width:30px;
                height:30px;
            }
            .embody_c em{
                margin: 0 20px 0 10px;
                color:#333;
                font-style: normal;
            }
    </style>
    <script type="text/javascript">
        $(function () {
            try
            {
                var lib = eval("("+$("#lib").attr("value")+")");
                var html = "";
                if (lib.err == 0) {
                    $.each(lib.data, function (i) {
                        var obj = lib.data[i];
                        //html += '<img src="' + obj.logo + '"/>' + obj.name + "&nbsp;&nbsp;";
                        html += ' <a href="' + obj.url + '" target="_blank">';
                        html += ' <img src="' + obj.logo + '">';
                        html += ' <em><b>' + obj.name + '</b></em>';
                        html += ' </a>';
                    });
                    if (html != "") {
                        setTimeout(function () {
                            $("#lib").html(html);                      
                            $("#embody").show();
                        }, 100);
                    }
                }      
            } catch (err)
            { }
            
        });
    </script>
      <div class="category clearfix">
        <div class="category_l">
           <img src="http://static.blog.csdn.net/images/category_icon.jpg">
            <span>分类:</span>
        </div>
        <div class="category_r">
                    <label onclick="GetCategoryArticles('5789635','catoop','top','50520958');">
                        <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">Spring<em>(42)</em></span>
                      <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;">
                      <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;">
                        <div class="subItem">
                            <div class="subItem_t"><a href="http://blog.csdn.net/catoop/article/category/5789635" target="_blank">作者同类文章</a><i class="J_close">X</i></div>
                            <ul class="subItem_l" id="top_5789635">                            
                            </ul>
                        </div>
                    </label>                    
        </div>
    </div>
        <div class="bog_copyright">         
            <p class="copyright_p">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
        </div>


  


  
  
     




<div id="article_content" class="article_content tracking-ad" data-mod="popu_307" data-dsm="post">
        <div class="markdown_views"><p>本来是打算接着写关于数据库方面,集成MyBatis的,刚好赶上朋友问到Shiro权限管理,就先总结下发出来了。</p>


<p>使用Shiro之前用在Spring MVC中,是通过XML文件进行配置。 <br>
既然现在在写Spring Boot的帖子,就将Shiro应用到Spring Boot中,我本地已经完成了SpringBoot使用Shiro的实例,将配置方法共享一下。</p>


<p>先简单介绍一下Shiro,对于没有用过Shiro的朋友,也算是做个简介吧。 <br>
Shiro是Apache下的一个开源项目,我们称之为Apache Shiro。它是一个很易用与Java项目的的安全框架,提供了认证、授权、加密、会话管理,与 Spring Security 一样都是做一个权限的安全框架,但是与Spring Security 相比,在于 Shiro 使用了比较简单易懂易于使用的授权方式。</p>


<p>Apache Shiro 的三大核心组件 <br>
<img src="http://img.blog.csdn.net/20160114233958301" alt="这里写图片描述" title=""> <br>
- Subject 当前用户操作 <br>
- SecurityManager 用于管理所有的Subject <br>
- Realms 用于进行权限信息的验证,也是我们需要自己实现的。</p>


<p>我们需要实现Realms的Authentication 和 Authorization。其中 Authentication 是用来验证用户身份,Authorization 是授权访问控制,用于对用户进行的操作授权,证明该用户是否允许进行当前操作,如访问某个链接,某个资源文件等。</p>


<p>Apache Shiro 核心通过 Filter 来实现,就好像SpringMvc 通过DispachServlet 来主控制一样。 <br>
既然是使用 Filter 一般也就能猜到,是通过URL规则来进行过滤和权限校验,所以我们需要定义一系列关于URL的规则和访问权限。</p>


<p>另外我们可以通过Shiro 提供的会话管理来获取Session中的信息。Shiro 也提供了缓存支持,使用 CacheManager 来管理。</p>


<p>官方网站:<a href="http://shiro.apache.org/" target="_blank">http://shiro.apache.org/</a> <br>
完整架构图: <br>
<img src="http://img.blog.csdn.net/20160114234018824" alt="这里写图片描述" title=""></p>


<p>下面我们通过代码实战来看下Spring Boot 中应用Shiro: <br>
1、创建数据库表 <br>
<img src="http://img.blog.csdn.net/20160114234036103" alt="这里写图片描述" title=""></p>






<pre class="prettyprint" name="code"><code class="hljs brainfuck has-numbering"><span class="hljs-comment">表(t_permission)</span>
    <span class="hljs-comment">id</span>  <span class="hljs-comment">permissionname</span>  <span class="hljs-comment">role_id</span>  
<span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>
     <span class="hljs-comment">1</span>  <span class="hljs-comment">add</span>                     <span class="hljs-comment">2</span>
     <span class="hljs-comment">2</span>  <span class="hljs-comment">del</span>                     <span class="hljs-comment">1</span>
     <span class="hljs-comment">3</span>  <span class="hljs-comment">update</span>                  <span class="hljs-comment">2</span>
     <span class="hljs-comment">4</span>  <span class="hljs-comment">query</span>                   <span class="hljs-comment">3</span>
     <span class="hljs-comment">5</span>  <span class="hljs-comment">user:query</span>              <span class="hljs-comment">1</span>
     <span class="hljs-comment">6</span>  <span class="hljs-comment">user:edit</span>               <span class="hljs-comment">2</span>


<span class="hljs-comment">表(t_role)</span>
    <span class="hljs-comment">id</span>  <span class="hljs-comment">rolename</span>  
<span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>
     <span class="hljs-comment">1</span>  <span class="hljs-comment">admin</span>     
     <span class="hljs-comment">2</span>  <span class="hljs-comment">manager</span>   
     <span class="hljs-comment">3</span>  <span class="hljs-comment">normal</span>    


<span class="hljs-comment">表(t_user)</span>
    <span class="hljs-comment">id</span>  <span class="hljs-comment">username</span>  <span class="hljs-comment">password</span>  
<span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>
     <span class="hljs-comment">1</span>  <span class="hljs-comment">tom</span>       <span class="hljs-comment">123456</span>    
     <span class="hljs-comment">2</span>  <span class="hljs-comment">jack</span>      <span class="hljs-comment">123456</span>    
     <span class="hljs-comment">3</span>  <span class="hljs-comment">rose</span>      <span class="hljs-comment">123456</span>  


<span class="hljs-comment">表(t_user_role)</span>
<span class="hljs-comment">user_id</span>  <span class="hljs-comment">role_id</span>  
<span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>  <span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span><span class="hljs-literal">-</span>
      <span class="hljs-comment">1</span>          <span class="hljs-comment">1</span>
      <span class="hljs-comment">1</span>          <span class="hljs-comment">3</span>
      <span class="hljs-comment">2</span>          <span class="hljs-comment">2</span>
      <span class="hljs-comment">2</span>          <span class="hljs-comment">3</span>
      <span class="hljs-comment">3</span>          <span class="hljs-comment">3</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li></ul></pre>


<p>看截图,上面3张表是我测试别的用的,可以忽略。</p>


<p>下面是,数据库脚本和测试数据。</p>






<pre class="prettyprint" name="code"><code class="hljs sql has-numbering"><span class="hljs-comment">/*
SQLyog Ultimate v10.00 Beta1
MySQL - 5.5.28 : Database - test
*********************************************************************
*/</span>




<span class="hljs-comment">/*!40101 SET NAMES utf8 */</span>;


<span class="hljs-comment">/*!40101 SET SQL_MODE=''*/</span>;


<span class="hljs-comment">/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */</span>;
<span class="hljs-comment">/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */</span>;
<span class="hljs-comment">/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */</span>;
<span class="hljs-comment">/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */</span>;
<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span> /*!<span class="hljs-number">32312</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span>*/<span class="hljs-string">`test`</span> /*!<span class="hljs-number">40100</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARACTER</span> <span class="hljs-keyword">SET</span> utf8 */;</span>


USE `test`;


<span class="hljs-comment">/*Table structure for table `t_permission` */</span>


<span class="hljs-operator"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-string">`t_permission`</span>;</span>


<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`t_permission`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`permissionname`</span> <span class="hljs-keyword">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-string">`role_id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-keyword">KEY</span> <span class="hljs-string">`id`</span> (<span class="hljs-string">`id`</span>)
) ENGINE=InnoDB AUTO_INCREMENT=<span class="hljs-number">7</span> <span class="hljs-keyword">DEFAULT</span> CHARSET=utf8;</span>


<span class="hljs-comment">/*Data for the table `t_permission` */</span>


<span class="hljs-operator"><span class="hljs-keyword">insert</span>  <span class="hljs-keyword">into</span> <span class="hljs-string">`t_permission`</span>(<span class="hljs-string">`id`</span>,<span class="hljs-string">`permissionname`</span>,<span class="hljs-string">`role_id`</span>) <span class="hljs-keyword">values</span> (<span class="hljs-number">1</span>,<span class="hljs-string">'add'</span>,<span class="hljs-number">2</span>),(<span class="hljs-number">2</span>,<span class="hljs-string">'del'</span>,<span class="hljs-number">1</span>),(<span class="hljs-number">3</span>,<span class="hljs-string">'update'</span>,<span class="hljs-number">2</span>),(<span class="hljs-number">4</span>,<span class="hljs-string">'query'</span>,<span class="hljs-number">3</span>),(<span class="hljs-number">5</span>,<span class="hljs-string">'user:query'</span>,<span class="hljs-number">1</span>),(<span class="hljs-number">6</span>,<span class="hljs-string">'user:edit'</span>,<span class="hljs-number">2</span>);</span>


<span class="hljs-comment">/*Table structure for table `t_role` */</span>


<span class="hljs-operator"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-string">`t_role`</span>;</span>


<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`t_role`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`rolename`</span> <span class="hljs-keyword">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-keyword">KEY</span> <span class="hljs-string">`id`</span> (<span class="hljs-string">`id`</span>)
) ENGINE=InnoDB AUTO_INCREMENT=<span class="hljs-number">4</span> <span class="hljs-keyword">DEFAULT</span> CHARSET=utf8;</span>


<span class="hljs-comment">/*Data for the table `t_role` */</span>


<span class="hljs-operator"><span class="hljs-keyword">insert</span>  <span class="hljs-keyword">into</span> <span class="hljs-string">`t_role`</span>(<span class="hljs-string">`id`</span>,<span class="hljs-string">`rolename`</span>) <span class="hljs-keyword">values</span> (<span class="hljs-number">1</span>,<span class="hljs-string">'admin'</span>),(<span class="hljs-number">2</span>,<span class="hljs-string">'manager'</span>),(<span class="hljs-number">3</span>,<span class="hljs-string">'normal'</span>);</span>


<span class="hljs-comment">/*Table structure for table `t_user` */</span>


<span class="hljs-operator"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-string">`t_user`</span>;</span>


<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`t_user`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`username`</span> <span class="hljs-keyword">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-string">`password`</span> <span class="hljs-keyword">varchar</span>(<span class="hljs-number">32</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-keyword">PRIMARY</span> <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>)
) ENGINE=InnoDB AUTO_INCREMENT=<span class="hljs-number">4</span> <span class="hljs-keyword">DEFAULT</span> CHARSET=utf8;</span>


<span class="hljs-comment">/*Data for the table `t_user` */</span>


<span class="hljs-operator"><span class="hljs-keyword">insert</span>  <span class="hljs-keyword">into</span> <span class="hljs-string">`t_user`</span>(<span class="hljs-string">`id`</span>,<span class="hljs-string">`username`</span>,<span class="hljs-string">`password`</span>) <span class="hljs-keyword">values</span> (<span class="hljs-number">1</span>,<span class="hljs-string">'tom'</span>,<span class="hljs-string">'123456'</span>),(<span class="hljs-number">2</span>,<span class="hljs-string">'jack'</span>,<span class="hljs-string">'123456'</span>),(<span class="hljs-number">3</span>,<span class="hljs-string">'rose'</span>,<span class="hljs-string">'123456'</span>);</span>


<span class="hljs-comment">/*Table structure for table `t_user_role` */</span>


<span class="hljs-operator"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-string">`t_user_role`</span>;</span>


<span class="hljs-operator"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`t_user_role`</span> (
  <span class="hljs-string">`user_id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>,
  <span class="hljs-string">`role_id`</span> <span class="hljs-keyword">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">NULL</span>
) ENGINE=InnoDB <span class="hljs-keyword">DEFAULT</span> CHARSET=utf8;</span>


<span class="hljs-comment">/*Data for the table `t_user_role` */</span>


<span class="hljs-operator"><span class="hljs-keyword">insert</span>  <span class="hljs-keyword">into</span> <span class="hljs-string">`t_user_role`</span>(<span class="hljs-string">`user_id`</span>,<span class="hljs-string">`role_id`</span>) <span class="hljs-keyword">values</span> (<span class="hljs-number">1</span>,<span class="hljs-number">1</span>),(<span class="hljs-number">1</span>,<span class="hljs-number">3</span>),(<span class="hljs-number">2</span>,<span class="hljs-number">2</span>),(<span class="hljs-number">2</span>,<span class="hljs-number">3</span>),(<span class="hljs-number">3</span>,<span class="hljs-number">3</span>);</span>


<span class="hljs-comment">/*!40101 SET SQL_MODE=@OLD_SQL_MODE */</span>;
<span class="hljs-comment">/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */</span>;
<span class="hljs-comment">/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */</span>;
<span class="hljs-comment">/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */</span>;
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li></ul></pre>


<p>2、创建对应实体类 <br>
User.java</p>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> org.springboot.sample.entity;


<span class="hljs-keyword">import</span> java.util.HashSet;
<span class="hljs-keyword">import</span> java.util.List;
<span class="hljs-keyword">import</span> java.util.Set;


<span class="hljs-keyword">import</span> javax.persistence.Entity;
<span class="hljs-keyword">import</span> javax.persistence.FetchType;
<span class="hljs-keyword">import</span> javax.persistence.GeneratedValue;
<span class="hljs-keyword">import</span> javax.persistence.GenerationType;
<span class="hljs-keyword">import</span> javax.persistence.Id;
<span class="hljs-keyword">import</span> javax.persistence.JoinColumn;
<span class="hljs-keyword">import</span> javax.persistence.JoinTable;
<span class="hljs-keyword">import</span> javax.persistence.ManyToMany;
<span class="hljs-keyword">import</span> javax.persistence.Table;
<span class="hljs-keyword">import</span> javax.persistence.Transient;


<span class="hljs-keyword">import</span> org.hibernate.validator.constraints.NotEmpty;


<span class="hljs-javadoc">/**
 * 用户
 *
 *<span class="hljs-javadoctag"> @author</span> 单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span> http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span> 2016年1月13日
 */</span>
<span class="hljs-annotation">@Entity</span>
<span class="hljs-annotation">@Table</span>(name = <span class="hljs-string">"t_user"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> {</span>


    <span class="hljs-annotation">@Id</span>
    <span class="hljs-annotation">@GeneratedValue</span>(strategy = GenerationType.IDENTITY)
    <span class="hljs-keyword">private</span> Integer id;
    <span class="hljs-annotation">@NotEmpty</span>(message = <span class="hljs-string">"用户名不能为空"</span>)
    <span class="hljs-keyword">private</span> String username;
    <span class="hljs-annotation">@NotEmpty</span>(message = <span class="hljs-string">"密码不能为空"</span>)
    <span class="hljs-keyword">private</span> String password;    
    <span class="hljs-annotation">@ManyToMany</span>(fetch=FetchType.EAGER)
    <span class="hljs-annotation">@JoinTable</span>(name = <span class="hljs-string">"t_user_role"</span>, joinColumns = { <span class="hljs-annotation">@JoinColumn</span>(name = <span class="hljs-string">"user_id"</span>) }, inverseJoinColumns = {
            <span class="hljs-annotation">@JoinColumn</span>(name = <span class="hljs-string">"role_id"</span>) })
    <span class="hljs-keyword">private</span> List&lt;Role&gt; roleList;<span class="hljs-comment">// 一个用户具有多个角色</span>


    <span class="hljs-keyword">public</span> <span class="hljs-title">User</span>() {
        <span class="hljs-keyword">super</span>();
    }


    <span class="hljs-keyword">public</span> <span class="hljs-title">User</span>(String username, String password) {
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">this</span>.username = username;
        <span class="hljs-keyword">this</span>.password = password;
    }


    <span class="hljs-comment">// 省略 get set 方法</span>


    <span class="hljs-annotation">@Transient</span>
    <span class="hljs-keyword">public</span> Set&lt;String&gt; <span class="hljs-title">getRolesName</span>() {
        List&lt;Role&gt; roles = getRoleList();
        Set&lt;String&gt; set = <span class="hljs-keyword">new</span> HashSet&lt;String&gt;();
        <span class="hljs-keyword">for</span> (Role role : roles) {
            set.add(role.getRolename());
        }
        <span class="hljs-keyword">return</span> set;
    }


}</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li></ul></pre>


<p>Role.java</p>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> org.springboot.sample.entity;


<span class="hljs-keyword">import</span> java.util.ArrayList;
<span class="hljs-keyword">import</span> java.util.List;


<span class="hljs-keyword">import</span> javax.persistence.Entity;
<span class="hljs-keyword">import</span> javax.persistence.FetchType;
<span class="hljs-keyword">import</span> javax.persistence.GeneratedValue;
<span class="hljs-keyword">import</span> javax.persistence.GenerationType;
<span class="hljs-keyword">import</span> javax.persistence.Id;
<span class="hljs-keyword">import</span> javax.persistence.JoinColumn;
<span class="hljs-keyword">import</span> javax.persistence.JoinTable;
<span class="hljs-keyword">import</span> javax.persistence.ManyToMany;
<span class="hljs-keyword">import</span> javax.persistence.OneToMany;
<span class="hljs-keyword">import</span> javax.persistence.Table;
<span class="hljs-keyword">import</span> javax.persistence.Transient;


<span class="hljs-javadoc">/**
 * 角色(管理员,普通用户等)
 *
 *<span class="hljs-javadoctag"> @author</span>   单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span>  http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span>    2016年1月13日
 */</span>
<span class="hljs-annotation">@Entity</span>
<span class="hljs-annotation">@Table</span>(name = <span class="hljs-string">"t_role"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Role</span> {</span>


    <span class="hljs-annotation">@Id</span>
    <span class="hljs-annotation">@GeneratedValue</span>(strategy = GenerationType.IDENTITY)
    <span class="hljs-keyword">private</span> Integer id;
    <span class="hljs-keyword">private</span> String rolename;
    <span class="hljs-annotation">@OneToMany</span>(mappedBy = <span class="hljs-string">"role"</span>, fetch=FetchType.EAGER)
    <span class="hljs-keyword">private</span> List&lt;Permission&gt; permissionList;<span class="hljs-comment">// 一个角色对应多个权限</span>
    <span class="hljs-annotation">@ManyToMany</span>
    <span class="hljs-annotation">@JoinTable</span>(name = <span class="hljs-string">"t_user_role"</span>, joinColumns = { <span class="hljs-annotation">@JoinColumn</span>(name = <span class="hljs-string">"role_id"</span>) }, inverseJoinColumns = {
            <span class="hljs-annotation">@JoinColumn</span>(name = <span class="hljs-string">"user_id"</span>) })
    <span class="hljs-keyword">private</span> List&lt;User&gt; userList;<span class="hljs-comment">// 一个角色对应多个用户</span>


    <span class="hljs-comment">// 省略 get set 方法</span>


    <span class="hljs-annotation">@Transient</span>
    <span class="hljs-keyword">public</span> List&lt;String&gt; <span class="hljs-title">getPermissionsName</span>() {
        List&lt;String&gt; list = <span class="hljs-keyword">new</span> ArrayList&lt;String&gt;();
        List&lt;Permission&gt; perlist = getPermissionList();
        <span class="hljs-keyword">for</span> (Permission per : perlist) {
            list.add(per.getPermissionname());
        }
        <span class="hljs-keyword">return</span> list;
    }
}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li></ul></pre>


<p>Permission.java</p>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> org.springboot.sample.entity;


<span class="hljs-keyword">import</span> javax.persistence.Entity;
<span class="hljs-keyword">import</span> javax.persistence.GeneratedValue;
<span class="hljs-keyword">import</span> javax.persistence.GenerationType;
<span class="hljs-keyword">import</span> javax.persistence.Id;
<span class="hljs-keyword">import</span> javax.persistence.JoinColumn;
<span class="hljs-keyword">import</span> javax.persistence.ManyToOne;
<span class="hljs-keyword">import</span> javax.persistence.Table;


<span class="hljs-javadoc">/**
 * 权限(增删改查等)
 *
 *<span class="hljs-javadoctag"> @author</span> 单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span> http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span> 2016年1月13日
 */</span>
<span class="hljs-annotation">@Entity</span>
<span class="hljs-annotation">@Table</span>(name = <span class="hljs-string">"t_permission"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Permission</span> {</span>


    <span class="hljs-annotation">@Id</span>
    <span class="hljs-annotation">@GeneratedValue</span>(strategy = GenerationType.IDENTITY)
    <span class="hljs-keyword">private</span> Integer id;
    <span class="hljs-keyword">private</span> String permissionname;


    <span class="hljs-annotation">@ManyToOne</span>
    <span class="hljs-annotation">@JoinColumn</span>(name = <span class="hljs-string">"role_id"</span>)
    <span class="hljs-keyword">private</span> Role role;<span class="hljs-comment">// 一个权限对应一个角色</span>


    <span class="hljs-comment">// 省略 get set</span>


}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li></ul></pre>


<p>3、Shiro 配置,相当于SpringMVC 中的XML配置 <br>
ShiroConfiguration.java</p>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> org.springboot.sample.config;


<span class="hljs-keyword">import</span> java.util.LinkedHashMap;
<span class="hljs-keyword">import</span> java.util.Map;


<span class="hljs-keyword">import</span> org.apache.shiro.cache.ehcache.EhCacheManager;
<span class="hljs-keyword">import</span> org.apache.shiro.spring.LifecycleBeanPostProcessor;
<span class="hljs-keyword">import</span> org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
<span class="hljs-keyword">import</span> org.apache.shiro.spring.web.ShiroFilterFactoryBean;
<span class="hljs-keyword">import</span> org.apache.shiro.web.mgt.DefaultWebSecurityManager;
<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;
<span class="hljs-keyword">import</span> org.springboot.sample.dao.IScoreDao;
<span class="hljs-keyword">import</span> org.springboot.sample.security.MyShiroRealm;
<span class="hljs-keyword">import</span> org.springboot.sample.service.StudentService;
<span class="hljs-keyword">import</span> org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
<span class="hljs-keyword">import</span> org.springframework.boot.context.embedded.FilterRegistrationBean;
<span class="hljs-keyword">import</span> org.springframework.context.annotation.Bean;
<span class="hljs-keyword">import</span> org.springframework.context.annotation.Configuration;
<span class="hljs-keyword">import</span> org.springframework.web.filter.DelegatingFilterProxy;


<span class="hljs-javadoc">/**
 * Shiro 配置
 *
 *<span class="hljs-javadoctag"> @author</span>   单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span>  http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span>    2016年1月13日
 */</span>
<span class="hljs-annotation">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ShiroConfiguration</span> {</span>


    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger logger = LoggerFactory.getLogger(ShiroConfiguration.class);


    <span class="hljs-annotation">@Bean</span>
    <span class="hljs-keyword">public</span> EhCacheManager <span class="hljs-title">getEhCacheManager</span>() {  
        EhCacheManager em = <span class="hljs-keyword">new</span> EhCacheManager();  
        em.setCacheManagerConfigFile(<span class="hljs-string">"classpath:ehcache-shiro.xml"</span>);  
        <span class="hljs-keyword">return</span> em;  
    }  


    <span class="hljs-annotation">@Bean</span>(name = <span class="hljs-string">"myShiroRealm"</span>)
    <span class="hljs-keyword">public</span> MyShiroRealm <span class="hljs-title">myShiroRealm</span>(EhCacheManager cacheManager) {  
        MyShiroRealm realm = <span class="hljs-keyword">new</span> MyShiroRealm(); 
        realm.setCacheManager(cacheManager);
        <span class="hljs-keyword">return</span> realm;
    }  


    <span class="hljs-javadoc">/**
     * 注册DelegatingFilterProxy(Shiro)
     * 集成Shiro有2种方法:
     * 1. 按这个方法自己组装一个FilterRegistrationBean(这种方法更为灵活,可以自己定义UrlPattern,
     * 在项目使用中你可能会因为一些很但疼的问题最后采用它, 想使用它你可能需要看官网或者已经很了解Shiro的处理原理了)
     * 2. 直接使用ShiroFilterFactoryBean(这种方法比较简单,其内部对ShiroFilter做了组装工作,无法自己定义UrlPattern,
     * 默认拦截 /*)
     *
     *<span class="hljs-javadoctag"> @param</span> dispatcherServlet
     *<span class="hljs-javadoctag"> @return</span>
     *<span class="hljs-javadoctag"> @author</span> SHANHY
     *<span class="hljs-javadoctag"> @create</span>  2016年1月13日
     */</span>
<span class="hljs-comment">//  @Bean</span>
<span class="hljs-comment">//  public FilterRegistrationBean filterRegistrationBean() {</span>
<span class="hljs-comment">//      FilterRegistrationBean filterRegistration = new FilterRegistrationBean();</span>
<span class="hljs-comment">//      filterRegistration.setFilter(new DelegatingFilterProxy("shiroFilter"));</span>
<span class="hljs-comment">//      //  该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由ServletContainer管理  </span>
<span class="hljs-comment">//      filterRegistration.addInitParameter("targetFilterLifecycle", "true");</span>
<span class="hljs-comment">//      filterRegistration.setEnabled(true);</span>
<span class="hljs-comment">//      filterRegistration.addUrlPatterns("/*");// 可以自己灵活的定义很多,避免一些根本不需要被Shiro处理的请求被包含进来</span>
<span class="hljs-comment">//      return filterRegistration;</span>
<span class="hljs-comment">//  }</span>


    <span class="hljs-annotation">@Bean</span>(name = <span class="hljs-string">"lifecycleBeanPostProcessor"</span>)
    <span class="hljs-keyword">public</span> LifecycleBeanPostProcessor <span class="hljs-title">getLifecycleBeanPostProcessor</span>() {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> LifecycleBeanPostProcessor();
    }


    <span class="hljs-annotation">@Bean</span>
    <span class="hljs-keyword">public</span> DefaultAdvisorAutoProxyCreator <span class="hljs-title">getDefaultAdvisorAutoProxyCreator</span>() {
        DefaultAdvisorAutoProxyCreator daap = <span class="hljs-keyword">new</span> DefaultAdvisorAutoProxyCreator();
        daap.setProxyTargetClass(<span class="hljs-keyword">true</span>);
        <span class="hljs-keyword">return</span> daap;
    }


    <span class="hljs-annotation">@Bean</span>(name = <span class="hljs-string">"securityManager"</span>)
    <span class="hljs-keyword">public</span> DefaultWebSecurityManager <span class="hljs-title">getDefaultWebSecurityManager</span>(MyShiroRealm myShiroRealm) {
        DefaultWebSecurityManager dwsm = <span class="hljs-keyword">new</span> DefaultWebSecurityManager();
        dwsm.setRealm(myShiroRealm);
<span class="hljs-comment">//      &lt;!-- 用户授权/认证信息Cache, 采用EhCache 缓存 --&gt; </span>
        dwsm.setCacheManager(getEhCacheManager());
        <span class="hljs-keyword">return</span> dwsm;
    }


    <span class="hljs-annotation">@Bean</span>
    <span class="hljs-keyword">public</span> AuthorizationAttributeSourceAdvisor <span class="hljs-title">getAuthorizationAttributeSourceAdvisor</span>(DefaultWebSecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor aasa = <span class="hljs-keyword">new</span> AuthorizationAttributeSourceAdvisor();
        aasa.setSecurityManager(securityManager);
        <span class="hljs-keyword">return</span> aasa;
    }


    <span class="hljs-javadoc">/**
     * 加载shiroFilter权限控制规则(从数据库读取然后配置)
     *
     *<span class="hljs-javadoctag"> @author</span> SHANHY
     *<span class="hljs-javadoctag"> @create</span>  2016年1月14日
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">loadShiroFilterChain</span>(ShiroFilterFactoryBean shiroFilterFactoryBean, StudentService stuService, IScoreDao scoreDao){
        <span class="hljs-comment">/////////////////////// 下面这些规则配置最好配置到配置文件中 ///////////////////////</span>
        Map&lt;String, String&gt; filterChainDefinitionMap = <span class="hljs-keyword">new</span> LinkedHashMap&lt;String, String&gt;();
        <span class="hljs-comment">// authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter</span>
        filterChainDefinitionMap.put(<span class="hljs-string">"/user"</span>, <span class="hljs-string">"authc"</span>);<span class="hljs-comment">// 这里为了测试,只限制/user,实际开发中请修改为具体拦截的请求规则</span>
        <span class="hljs-comment">// anon:它对应的过滤器里面是空的,什么都没做</span>
        logger.info(<span class="hljs-string">"##################从数据库读取权限规则,加载到shiroFilter中##################"</span>);
        filterChainDefinitionMap.put(<span class="hljs-string">"/user/edit/**"</span>, <span class="hljs-string">"authc,perms[user:edit]"</span>);<span class="hljs-comment">// 这里为了测试,固定写死的值,也可以从数据库或其他配置中读取</span>


        filterChainDefinitionMap.put(<span class="hljs-string">"/login"</span>, <span class="hljs-string">"anon"</span>);
        filterChainDefinitionMap.put(<span class="hljs-string">"/**"</span>, <span class="hljs-string">"anon"</span>);<span class="hljs-comment">//anon 可以理解为不拦截</span>


        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
    }


    <span class="hljs-javadoc">/**
     * ShiroFilter&lt;br/&gt;
     * 注意这里参数中的 StudentService 和 IScoreDao 只是一个例子,因为我们在这里可以用这样的方式获取到相关访问数据库的对象,
     * 然后读取数据库相关配置,配置到 shiroFilterFactoryBean 的访问规则中。实际项目中,请使用自己的Service来处理业务逻辑。
     *
     *<span class="hljs-javadoctag"> @param</span> myShiroRealm
     *<span class="hljs-javadoctag"> @param</span> stuService
     *<span class="hljs-javadoctag"> @param</span> scoreDao
     *<span class="hljs-javadoctag"> @return</span>
     *<span class="hljs-javadoctag"> @author</span> SHANHY
     *<span class="hljs-javadoctag"> @create</span>  2016年1月14日
     */</span>
    <span class="hljs-annotation">@Bean</span>(name = <span class="hljs-string">"shiroFilter"</span>)
    <span class="hljs-keyword">public</span> ShiroFilterFactoryBean <span class="hljs-title">getShiroFilterFactoryBean</span>(DefaultWebSecurityManager securityManager, StudentService stuService, IScoreDao scoreDao) {


        ShiroFilterFactoryBean shiroFilterFactoryBean = <span class="hljs-keyword">new</span> MShiroFilterFactoryBean();
        <span class="hljs-comment">// 必须设置 SecurityManager  </span>
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        <span class="hljs-comment">// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面</span>
        shiroFilterFactoryBean.setLoginUrl(<span class="hljs-string">"/login"</span>);
        <span class="hljs-comment">// 登录成功后要跳转的连接</span>
        shiroFilterFactoryBean.setSuccessUrl(<span class="hljs-string">"/user"</span>);
        shiroFilterFactoryBean.setUnauthorizedUrl(<span class="hljs-string">"/403"</span>);


        loadShiroFilterChain(shiroFilterFactoryBean, stuService, scoreDao);
        <span class="hljs-keyword">return</span> shiroFilterFactoryBean;
    }


}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li><li>82</li><li>83</li><li>84</li><li>85</li><li>86</li><li>87</li><li>88</li><li>89</li><li>90</li><li>91</li><li>92</li><li>93</li><li>94</li><li>95</li><li>96</li><li>97</li><li>98</li><li>99</li><li>100</li><li>101</li><li>102</li><li>103</li><li>104</li><li>105</li><li>106</li><li>107</li><li>108</li><li>109</li><li>110</li><li>111</li><li>112</li><li>113</li><li>114</li><li>115</li><li>116</li><li>117</li><li>118</li><li>119</li><li>120</li><li>121</li><li>122</li><li>123</li><li>124</li><li>125</li><li>126</li><li>127</li><li>128</li><li>129</li><li>130</li><li>131</li><li>132</li><li>133</li><li>134</li><li>135</li><li>136</li><li>137</li><li>138</li><li>139</li><li>140</li><li>141</li><li>142</li><li>143</li><li>144</li><li>145</li><li>146</li><li>147</li><li>148</li><li>149</li><li>150</li></ul></pre>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering">
<span class="hljs-javadoc">/**
 * 继承 ShiroFilterFactoryBean 处理拦截资源文件问题。
 *
 *<span class="hljs-javadoctag"> @author</span>   单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span>  http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span>    2016年3月8日
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MShiroFilterFactoryBean</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ShiroFilterFactoryBean</span> {</span>


    <span class="hljs-comment">// 对ShiroFilter来说,需要直接忽略的请求</span>
    <span class="hljs-keyword">private</span> Set&lt;String&gt; ignoreExt;


    <span class="hljs-keyword">public</span> <span class="hljs-title">MShiroFilterFactoryBean</span>() {
        <span class="hljs-keyword">super</span>();
        ignoreExt = <span class="hljs-keyword">new</span> HashSet&lt;&gt;();
        ignoreExt.add(<span class="hljs-string">".jpg"</span>);
        ignoreExt.add(<span class="hljs-string">".png"</span>);
        ignoreExt.add(<span class="hljs-string">".gif"</span>);
        ignoreExt.add(<span class="hljs-string">".bmp"</span>);
        ignoreExt.add(<span class="hljs-string">".js"</span>);
        ignoreExt.add(<span class="hljs-string">".css"</span>);
    }


    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> AbstractShiroFilter <span class="hljs-title">createInstance</span>() <span class="hljs-keyword">throws</span> Exception {


        SecurityManager securityManager = getSecurityManager();
        <span class="hljs-keyword">if</span> (securityManager == <span class="hljs-keyword">null</span>) {
            String msg = <span class="hljs-string">"SecurityManager property must be set."</span>;
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> BeanInitializationException(msg);
        }


        <span class="hljs-keyword">if</span> (!(securityManager <span class="hljs-keyword">instanceof</span> WebSecurityManager)) {
            String msg = <span class="hljs-string">"The security manager does not implement the WebSecurityManager interface."</span>;
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> BeanInitializationException(msg);
        }


        FilterChainManager manager = createFilterChainManager();


        PathMatchingFilterChainResolver chainResolver = <span class="hljs-keyword">new</span> PathMatchingFilterChainResolver();
        chainResolver.setFilterChainManager(manager);


        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> MSpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
    }


    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MSpringShiroFilter</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractShiroFilter</span> {</span>


        <span class="hljs-keyword">protected</span> <span class="hljs-title">MSpringShiroFilter</span>(WebSecurityManager webSecurityManager, FilterChainResolver resolver) {
            <span class="hljs-keyword">super</span>();
            <span class="hljs-keyword">if</span> (webSecurityManager == <span class="hljs-keyword">null</span>) {
                <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> IllegalArgumentException(<span class="hljs-string">"WebSecurityManager property cannot be null."</span>);
            }
            setSecurityManager(webSecurityManager);
            <span class="hljs-keyword">if</span> (resolver != <span class="hljs-keyword">null</span>) {
                setFilterChainResolver(resolver);
            }
        }


        <span class="hljs-annotation">@Override</span>
        <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doFilterInternal</span>(ServletRequest servletRequest, ServletResponse servletResponse,
                FilterChain chain) <span class="hljs-keyword">throws</span> ServletException, IOException {
            HttpServletRequest request = (HttpServletRequest)servletRequest;
            String str = request.getRequestURI().toLowerCase();
            <span class="hljs-comment">// 因为ShiroFilter 拦截所有请求(在上面我们配置了urlPattern 为 * ,当然你也可以在那里精确的添加要处理的路径,这样就不需要这个类了),而在每次请求里面都做了session的读取和更新访问时间等操作,这样在集群部署session共享的情况下,数量级的加大了处理量负载。</span>
            <span class="hljs-comment">// 所以我们这里将一些能忽略的请求忽略掉。</span>
            <span class="hljs-comment">// 当然如果你的集群系统使用了动静分离处理,静态资料的请求不会到Filter这个层面,便可以忽略。</span>
            <span class="hljs-keyword">boolean</span> flag = <span class="hljs-keyword">true</span>;
            <span class="hljs-keyword">int</span> idx = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">if</span>(( idx = str.indexOf(<span class="hljs-string">"."</span>)) &gt; <span class="hljs-number">0</span>){
                str = str.substring(idx);
                <span class="hljs-keyword">if</span>(ignoreExt.contains(str.toLowerCase()))
                    flag = <span class="hljs-keyword">false</span>;
            }
            <span class="hljs-keyword">if</span>(flag){
                <span class="hljs-keyword">super</span>.doFilterInternal(servletRequest, servletResponse, chain);
            }<span class="hljs-keyword">else</span>{
                chain.doFilter(servletRequest, servletResponse);
            }
        }


    }
}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li><li>82</li><li>83</li><li>84</li></ul></pre>


<p>其中的 ehcache-shiro.xml 在 src/main/resources 下面,内容为:</p>






<pre class="prettyprint" name="code"><code class="hljs xml has-numbering"><span class="hljs-pi">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">ehcache</span> <span class="hljs-attribute">updateCheck</span>=<span class="hljs-value">"false"</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"shiroCache"</span>&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-title">defaultCache
</span>            <span class="hljs-attribute">maxElementsInMemory</span>=<span class="hljs-value">"10000"</span>
            <span class="hljs-attribute">eternal</span>=<span class="hljs-value">"false"</span>
            <span class="hljs-attribute">timeToIdleSeconds</span>=<span class="hljs-value">"120"</span>
            <span class="hljs-attribute">timeToLiveSeconds</span>=<span class="hljs-value">"120"</span>
            <span class="hljs-attribute">overflowToDisk</span>=<span class="hljs-value">"false"</span>
            <span class="hljs-attribute">diskPersistent</span>=<span class="hljs-value">"false"</span>
            <span class="hljs-attribute">diskExpiryThreadIntervalSeconds</span>=<span class="hljs-value">"120"</span>
            /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">ehcache</span>&gt;</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li></ul></pre>


<p>4、继承 AuthorizingRealm 实现认证和授权2个方法 <br>
MyShiroRealm.java</p>






<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> org.springboot.sample.security;


<span class="hljs-keyword">import</span> java.util.List;


<span class="hljs-keyword">import</span> org.apache.commons.lang3.builder.ReflectionToStringBuilder;
<span class="hljs-keyword">import</span> org.apache.commons.lang3.builder.ToStringStyle;
<span class="hljs-keyword">import</span> org.apache.shiro.authc.AuthenticationException;
<span class="hljs-keyword">import</span> org.apache.shiro.authc.AuthenticationInfo;
<span class="hljs-keyword">import</span> org.apache.shiro.authc.AuthenticationToken;
<span class="hljs-keyword">import</span> org.apache.shiro.authc.SimpleAuthenticationInfo;
<span class="hljs-keyword">import</span> org.apache.shiro.authc.UsernamePasswordToken;
<span class="hljs-keyword">import</span> org.apache.shiro.authz.AuthorizationInfo;
<span class="hljs-keyword">import</span> org.apache.shiro.authz.SimpleAuthorizationInfo;
<span class="hljs-keyword">import</span> org.apache.shiro.realm.AuthorizingRealm;
<span class="hljs-keyword">import</span> org.apache.shiro.subject.PrincipalCollection;
<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;
<span class="hljs-keyword">import</span> org.springboot.sample.dao.IUserDao;
<span class="hljs-keyword">import</span> org.springboot.sample.entity.Role;
<span class="hljs-keyword">import</span> org.springboot.sample.entity.User;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Service;
<span class="hljs-keyword">import</span> org.springframework.transaction.annotation.Transactional;


<span class="hljs-javadoc">/**
 * MyShiroRealm
 *
 *<span class="hljs-javadoctag"> @author</span>   单红宇(365384722)
 *<span class="hljs-javadoctag"> @myblog</span>  http://blog.csdn.net/catoop/
 *<span class="hljs-javadoctag"> @create</span>    2016年1月13日
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyShiroRealm</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AuthorizingRealm</span>{</span>


    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger logger = LoggerFactory.getLogger(MyShiroRealm.class);


    <span class="hljs-annotation">@Autowired</span>
    <span class="hljs-keyword">private</span> IUserDao userDao; 


    <span class="hljs-javadoc">/**
     * 权限认证,为当前登录的Subject授予角色和权限 
     *<span class="hljs-javadoctag"> @see</span> 经测试:本例中该方法的调用时机为需授权资源被访问时 
     *<span class="hljs-javadoctag"> @see</span> 经测试:并且每次访问需授权资源时都会执行该方法中的逻辑,这表明本例中默认并未启用AuthorizationCache 
     *<span class="hljs-javadoctag"> @see</span> 经测试:如果连续访问同一个URL(比如刷新),该方法不会被重复调用,Shiro有一个时间间隔(也就是cache时间,在ehcache-shiro.xml中配置),超过这个时间间隔再刷新页面,该方法会被执行
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> AuthorizationInfo <span class="hljs-title">doGetAuthorizationInfo</span>(PrincipalCollection principalCollection) {
        logger.info(<span class="hljs-string">"##################执行Shiro权限认证##################"</span>);
        <span class="hljs-comment">//获取当前登录输入的用户名,等价于(String) principalCollection.fromRealm(getName()).iterator().next();</span>
        String loginName = (String)<span class="hljs-keyword">super</span>.getAvailablePrincipal(principalCollection); 
        <span class="hljs-comment">//到数据库查是否有此对象</span>
        User user=userDao.findByName(loginName);<span class="hljs-comment">// 实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法</span>
        <span class="hljs-keyword">if</span>(user!=<span class="hljs-keyword">null</span>){
            <span class="hljs-comment">//权限信息对象info,用来存放查出的用户的所有的角色(role)及权限(permission)</span>
            SimpleAuthorizationInfo info=<span class="hljs-keyword">new</span> SimpleAuthorizationInfo();
            <span class="hljs-comment">//用户的角色集合</span>
            info.setRoles(user.getRolesName());
            <span class="hljs-comment">//用户的角色对应的所有权限,如果只使用角色定义访问权限,下面的四行可以不要</span>
            List&lt;Role&gt; roleList=user.getRoleList();
            <span class="hljs-keyword">for</span> (Role role : roleList) {
                info.addStringPermissions(role.getPermissionsName());
            }
            <span class="hljs-comment">// 或者按下面这样添加</span>
            <span class="hljs-comment">//添加一个角色,不是配置意义上的添加,而是证明该用户拥有admin角色    </span>
<span class="hljs-comment">//            simpleAuthorInfo.addRole("admin");  </span>
            <span class="hljs-comment">//添加权限  </span>
<span class="hljs-comment">//            simpleAuthorInfo.addStringPermission("admin:manage");  </span>
<span class="hljs-comment">//            logger.info("已为用户[mike]赋予了[admin]角色和[admin:manage]权限");</span>
            <span class="hljs-keyword">return</span> info;
        }
        <span class="hljs-comment">// 返回null的话,就会导致任何用户访问被拦截的请求时,都会自动跳转到unauthorizedUrl指定的地址</span>
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }


    <span class="hljs-javadoc">/**
     * 登录认证
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> AuthenticationInfo <span class="hljs-title">doGetAuthenticationInfo</span>(
            AuthenticationToken authenticationToken) <span class="hljs-keyword">throws</span> AuthenticationException {
        <span class="hljs-comment">//UsernamePasswordToken对象用来存放提交的登录信息</span>
        UsernamePasswordToken token=(UsernamePasswordToken) authenticationToken;


        logger.info(<span class="hljs-string">"验证当前Subject时获取到token为:"</span> + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE)); 


        <span class="hljs-comment">//查出是否有此用户</span>
        User user=userDao.findByName(token.getUsername());
        <span class="hljs-keyword">if</span>(user!=<span class="hljs-keyword">null</span>){
            <span class="hljs-comment">// 若存在,将此用户存放到登录认证info中,无需自己做密码对比,Shiro会为我们进行密码对比校验</span>
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName());
        }
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li><li>82</li><li>83</li><li>84</li><li>85</li><li>86</li><li>87</li><li>88</li><li>89</li><li>90</li><li>91</li><li>92</li><li>93</li><li>94</li></ul></pre>


<p>注意:其中 userDao.findByName 这个代码就不贴上了,也没啥可贴的,根据姓名查询一个对象而已。</p>


<p>5、编写测试的 Controller 和测试 jsp 页面 <br>
ShiroController.java</p>






<pre class="prettyprint" name="code"><code class="hljs avrasm has-numbering">package org<span class="hljs-preprocessor">.springboot</span><span class="hljs-preprocessor">.sample</span><span class="hljs-preprocessor">.controller</span><span class="hljs-comment">;</span>


import java<span class="hljs-preprocessor">.util</span><span class="hljs-preprocessor">.Map</span><span class="hljs-comment">;</span>


import javax<span class="hljs-preprocessor">.validation</span><span class="hljs-preprocessor">.Valid</span><span class="hljs-comment">;</span>


import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.SecurityUtils</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.AuthenticationException</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.ExcessiveAttemptsException</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.IncorrectCredentialsException</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.LockedAccountException</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.UnknownAccountException</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.authc</span><span class="hljs-preprocessor">.UsernamePasswordToken</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.apache</span><span class="hljs-preprocessor">.shiro</span><span class="hljs-preprocessor">.subject</span><span class="hljs-preprocessor">.Subject</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.slf</span>4j<span class="hljs-preprocessor">.Logger</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.slf</span>4j<span class="hljs-preprocessor">.LoggerFactory</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springboot</span><span class="hljs-preprocessor">.sample</span><span class="hljs-preprocessor">.dao</span><span class="hljs-preprocessor">.IUserDao</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springboot</span><span class="hljs-preprocessor">.sample</span><span class="hljs-preprocessor">.entity</span><span class="hljs-preprocessor">.User</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.beans</span><span class="hljs-preprocessor">.factory</span><span class="hljs-preprocessor">.annotation</span><span class="hljs-preprocessor">.Autowired</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.stereotype</span><span class="hljs-preprocessor">.Controller</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.ui</span><span class="hljs-preprocessor">.Model</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.validation</span><span class="hljs-preprocessor">.BindingResult</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.web</span><span class="hljs-preprocessor">.bind</span><span class="hljs-preprocessor">.annotation</span><span class="hljs-preprocessor">.PathVariable</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.web</span><span class="hljs-preprocessor">.bind</span><span class="hljs-preprocessor">.annotation</span><span class="hljs-preprocessor">.RequestMapping</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.web</span><span class="hljs-preprocessor">.bind</span><span class="hljs-preprocessor">.annotation</span><span class="hljs-preprocessor">.RequestMethod</span><span class="hljs-comment">;</span>
import org<span class="hljs-preprocessor">.springframework</span><span class="hljs-preprocessor">.web</span><span class="hljs-preprocessor">.servlet</span><span class="hljs-preprocessor">.mvc</span><span class="hljs-preprocessor">.support</span><span class="hljs-preprocessor">.RedirectAttributes</span><span class="hljs-comment">;</span>


<span class="hljs-comment">/**
 * Shiro测试Controller
 *
 * @author   单红宇(365384722)
 * @myblog  http://blog.csdn.net/catoop/
 * @create    2016年1月13日
 */</span>
@Controller
public class ShiroController {


    private static final Logger logger = LoggerFactory<span class="hljs-preprocessor">.getLogger</span>(ShiroController<span class="hljs-preprocessor">.class</span>)<span class="hljs-comment">;</span>


    @Autowired
    private IUserDao userDao<span class="hljs-comment">;</span>


    @RequestMapping(value=<span class="hljs-string">"/login"</span>,method=RequestMethod<span class="hljs-preprocessor">.GET</span>)
    public String loginForm(Model model){
        model<span class="hljs-preprocessor">.addAttribute</span>(<span class="hljs-string">"user"</span>, new User())<span class="hljs-comment">;</span>
        return <span class="hljs-string">"login"</span><span class="hljs-comment">;</span>
    }


    @RequestMapping(value=<span class="hljs-string">"/login"</span>,method=RequestMethod<span class="hljs-preprocessor">.POST</span>)
    public String login(@Valid User user,BindingResult bindingResult,RedirectAttributes redirectAttributes){
        if(bindingResult<span class="hljs-preprocessor">.hasErrors</span>()){
            return <span class="hljs-string">"login"</span><span class="hljs-comment">;</span>
        }


        String username = user<span class="hljs-preprocessor">.getUsername</span>()<span class="hljs-comment">;</span>
        UsernamePasswordToken token = new UsernamePasswordToken(user<span class="hljs-preprocessor">.getUsername</span>(), user<span class="hljs-preprocessor">.getPassword</span>())<span class="hljs-comment">;</span>
        //获取当前的Subject  
        Subject currentUser = SecurityUtils<span class="hljs-preprocessor">.getSubject</span>()<span class="hljs-comment">;  </span>
        try {  
            //在调用了login方法后,SecurityManager会收到AuthenticationToken,并将其发送给已配置的Realm执行必须的认证检查  
            //每个Realm都能在必要时对提交的AuthenticationTokens作出反应  
            //所以这一步在调用login(token)方法时,它会走到MyRealm<span class="hljs-preprocessor">.doGetAuthenticationInfo</span>()方法中,具体验证方式详见此方法  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证开始"</span>)<span class="hljs-comment">;  </span>
            currentUser<span class="hljs-preprocessor">.login</span>(token)<span class="hljs-comment">;  </span>
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证通过"</span>)<span class="hljs-comment">;  </span>
        }catch(UnknownAccountException uae){  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证未通过,未知账户"</span>)<span class="hljs-comment">;  </span>
            redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"未知账户"</span>)<span class="hljs-comment">;  </span>
        }catch(IncorrectCredentialsException ice){  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证未通过,错误的凭证"</span>)<span class="hljs-comment">;  </span>
            redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"密码不正确"</span>)<span class="hljs-comment">;  </span>
        }catch(LockedAccountException lae){  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证未通过,账户已锁定"</span>)<span class="hljs-comment">;  </span>
            redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"账户已锁定"</span>)<span class="hljs-comment">;  </span>
        }catch(ExcessiveAttemptsException eae){  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证未通过,错误次数过多"</span>)<span class="hljs-comment">;  </span>
            redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"用户名或密码错误次数过多"</span>)<span class="hljs-comment">;  </span>
        }catch(AuthenticationException ae){  
            //通过处理Shiro的运行时AuthenticationException就可以控制用户登录失败或密码错误时的情景  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"对用户["</span> + username + <span class="hljs-string">"]进行登录验证..验证未通过,堆栈轨迹如下"</span>)<span class="hljs-comment">;  </span>
            ae<span class="hljs-preprocessor">.printStackTrace</span>()<span class="hljs-comment">;  </span>
            redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"用户名或密码不正确"</span>)<span class="hljs-comment">;  </span>
        }  
        //验证是否登录成功  
        if(currentUser<span class="hljs-preprocessor">.isAuthenticated</span>()){  
            logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"用户["</span> + username + <span class="hljs-string">"]登录认证通过(这里可以进行一些认证通过后的一些系统参数初始化操作)"</span>)<span class="hljs-comment">;  </span>
            return <span class="hljs-string">"redirect:/user"</span><span class="hljs-comment">;</span>
        }else{  
            token<span class="hljs-preprocessor">.clear</span>()<span class="hljs-comment">;  </span>
            return <span class="hljs-string">"redirect:/login"</span><span class="hljs-comment">;</span>
        }  
    }


    @RequestMapping(value=<span class="hljs-string">"/logout"</span>,method=RequestMethod<span class="hljs-preprocessor">.GET</span>)  
    public String logout(RedirectAttributes redirectAttributes ){ 
        //使用权限管理工具进行用户的退出,跳出登录,给出提示信息
        SecurityUtils<span class="hljs-preprocessor">.getSubject</span>()<span class="hljs-preprocessor">.logout</span>()<span class="hljs-comment">;  </span>
        redirectAttributes<span class="hljs-preprocessor">.addFlashAttribute</span>(<span class="hljs-string">"message"</span>, <span class="hljs-string">"您已安全退出"</span>)<span class="hljs-comment">;  </span>
        return <span class="hljs-string">"redirect:/login"</span><span class="hljs-comment">;</span>
    } 


    @RequestMapping(<span class="hljs-string">"/403"</span>)
    public String unauthorizedRole(){
        logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"------没有权限-------"</span>)<span class="hljs-comment">;</span>
        return <span class="hljs-string">"403"</span><span class="hljs-comment">;</span>
    }


    @RequestMapping(<span class="hljs-string">"/user"</span>)
    public String getUserList(Map&lt;String, Object&gt; model){
        model<span class="hljs-preprocessor">.put</span>(<span class="hljs-string">"userList"</span>, userDao<span class="hljs-preprocessor">.getList</span>())<span class="hljs-comment">;</span>
        return <span class="hljs-string">"user"</span><span class="hljs-comment">;</span>
    }


    @RequestMapping(<span class="hljs-string">"/user/edit/{userid}"</span>)
    public String getUserList(@PathVariable int userid){
        logger<span class="hljs-preprocessor">.info</span>(<span class="hljs-string">"------进入用户信息修改-------"</span>)<span class="hljs-comment">;</span>
        return <span class="hljs-string">"user_edit"</span><span class="hljs-comment">;</span>
    }
}
</code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li><li>34</li><li>35</li><li>36</li><li>37</li><li>38</li><li>39</li><li>40</li><li>41</li><li>42</li><li>43</li><li>44</li><li>45</li><li>46</li><li>47</li><li>48</li><li>49</li><li>50</li><li>51</li><li>52</li><li>53</li><li>54</li><li>55</li><li>56</li><li>57</li><li>58</li><li>59</li><li>60</li><li>61</li><li>62</li><li>63</li><li>64</li><li>65</li><li>66</li><li>67</li><li>68</li><li>69</li><li>70</li><li>71</li><li>72</li><li>73</li><li>74</li><li>75</li><li>76</li><li>77</li><li>78</li><li>79</li><li>80</li><li>81</li><li>82</li><li>83</li><li>84</li><li>85</li><li>86</li><li>87</li><li>88</li><li>89</li><li>90</li><li>91</li><li>92</li><li>93</li><li>94</li><li>95</li><li>96</li><li>97</li><li>98</li><li>99</li><li>100</li><li>101</li><li>102</li><li>103</li><li>104</li><li>105</li><li>106</li><li>107</li><li>108</li><li>109</li><li>110</li><li>111</li><li>112</li><li>113</li><li>114</li><li>115</li><li>116</li><li>117</li><li>118</li><li>119</li><li>120</li></ul></pre>


<p>login.jsp</p>






<pre class="prettyprint" name="code"><code class="hljs xml has-numbering"><span class="vbscript">&lt;%@ page language=<span class="hljs-string">"java"</span> import=<span class="hljs-string">"java.util.*"</span> pageEncoding=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"form"</span> uri=<span class="hljs-string">"http://www.springframework.org/tags/form"</span>%&gt;</span>
<span class="hljs-doctype">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span>


<span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>登录页面----${message }<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">img</span> <span class="hljs-attribute">alt</span>=<span class="hljs-value">""</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"${pageContext.request.contextPath }/pic.jpg"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">form:form</span> <span class="hljs-attribute">action</span>=<span class="hljs-value">"${pageContext.request.contextPath }/login"</span>
        <span class="hljs-attribute">commandName</span>=<span class="hljs-value">"user"</span> <span class="hljs-attribute">method</span>=<span class="hljs-value">"post"</span>&gt;</span>
        用户名:<span class="hljs-tag">&lt;<span class="hljs-title">form:input</span> <span class="hljs-attribute">path</span>=<span class="hljs-value">"username"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">form:errors</span> <span class="hljs-attribute">path</span>=<span class="hljs-value">"username"</span> <span class="hljs-attribute">cssClass</span>=<span class="hljs-value">"error"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">br</span> /&gt;</span>
        密码:<span class="hljs-tag">&lt;<span class="hljs-title">form:password</span> <span class="hljs-attribute">path</span>=<span class="hljs-value">"password"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">form:errors</span> <span class="hljs-attribute">path</span>=<span class="hljs-value">"password"</span> <span class="hljs-attribute">cssClass</span>=<span class="hljs-value">"error"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">br</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">form:button</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"button"</span>&gt;</span>提交<span class="hljs-tag">&lt;/<span class="hljs-title">form:button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">form:form</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li></ul></pre>


<p>user.jsp</p>






<pre class="prettyprint" name="code"><code class="hljs xml has-numbering"><span class="vbscript">&lt;%@ page language=<span class="hljs-string">"java"</span> import=<span class="hljs-string">"java.util.*"</span> pageEncoding=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"c"</span> uri=<span class="hljs-string">"http://java.sun.com/jsp/jstl/core"</span> %&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"shiro"</span> uri=<span class="hljs-string">"http://shiro.apache.org/tags"</span> %&gt;</span>
<span class="hljs-doctype">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>用户列表<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>${message }<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>用户列表--<span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">"${pageContext.request.contextPath }/logout"</span>&gt;</span>退出登录<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>权限列表<span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:authenticated</span>&gt;</span>用户已经登录显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:authenticated</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasRole</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"manager"</span>&gt;</span>manager角色登录显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasRole</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasRole</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"admin"</span>&gt;</span>admin角色登录显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasRole</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasRole</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"normal"</span>&gt;</span>normal角色登录显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasRole</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasAnyRoles</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"manager,admin"</span>&gt;</span>manager or admin 角色用户登录显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasAnyRoles</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:principal</span>/&gt;</span>-显示当前登录用户名<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasPermission</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"add"</span>&gt;</span>add权限用户显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasPermission</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:hasPermission</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"user:query"</span>&gt;</span>user:query权限用户显示此内容<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:hasPermission</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">shiro:lacksPermission</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"user:query"</span>&gt;</span>不具有user:query权限的用户显示此内容 <span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">shiro:lacksPermission</span>&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>所有用户列表:<span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">c:forEach</span> <span class="hljs-attribute">items</span>=<span class="hljs-value">"${userList }"</span> <span class="hljs-attribute">var</span>=<span class="hljs-value">"user"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span>用户名:${user.username }----密码:${user.password }----<span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">"${pageContext.request.contextPath }/user/edit/${user.id}"</span>&gt;</span>修改用户(测试根据不同用户可访问权限不同,本例tom无权限,jack有权限)<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-title">c:forEach</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">img</span> <span class="hljs-attribute">alt</span>=<span class="hljs-value">""</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"${pageContext.request.contextPath }/pic.jpg"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text/javascript"</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"${pageContext.request.contextPath }/webjarslocator/jquery/jquery.js"</span>&gt;</span><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li><li>27</li><li>28</li><li>29</li><li>30</li><li>31</li><li>32</li><li>33</li></ul></pre>


<p>user_edit.jsp</p>






<pre class="prettyprint" name="code"><code class="hljs xml has-numbering"><span class="vbscript">&lt;%@ page language=<span class="hljs-string">"java"</span> import=<span class="hljs-string">"java.util.*"</span> pageEncoding=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"c"</span> uri=<span class="hljs-string">"http://java.sun.com/jsp/jstl/core"</span> %&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"shiro"</span> uri=<span class="hljs-string">"http://shiro.apache.org/tags"</span> %&gt;</span>
<span class="hljs-doctype">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>用户信息 - 修改<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h2</span>&gt;</span>修改用户信息页面<span class="hljs-tag">&lt;/<span class="hljs-title">h2</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">"${pageContext.request.contextPath }/user"</span>&gt;</span>返回用户列表<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li></ul></pre>


<p>403.jsp</p>






<pre class="prettyprint" name="code"><code class="hljs xml has-numbering"><span class="vbscript">&lt;%@ page language=<span class="hljs-string">"java"</span> import=<span class="hljs-string">"java.util.*"</span> pageEncoding=<span class="hljs-string">"UTF-8"</span>%&gt;</span>
<span class="vbscript">&lt;%@ taglib prefix=<span class="hljs-string">"form"</span> uri=<span class="hljs-string">"http://www.springframework.org/tags/form"</span> %&gt;</span>
<span class="hljs-doctype">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>权限错误<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span>


  <span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>对不起,您没有权限请求此连接!<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">img</span> <span class="hljs-attribute">alt</span>=<span class="hljs-value">""</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"${pageContext.request.contextPath }/pic.jpg"</span>&gt;</span>


  <span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span></code><ul class="pre-numbering" style=""><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li><li>13</li><li>14</li></ul></pre>


<p>其中的pic.jpg 是测试代码遗留的,没有任何用处。关于 Controller 和 JSP 页面本文不做介绍,关于Spring Boot 使用Controller 和 JSP ,前面已经有文章介绍。</p>


<p>启动服务后访问 <a href="http://localhost:8080/myspringboot/user" target="_blank">http://localhost:8080/myspringboot/user</a> 会自动跳到 login 页面。 <br>
登录成功后,会打开 user 页面(关于默认登录页、成功成功URL、没有权限URL,在 ShiroConfiguration 中已经配置)。 <br>
在 user 页面上,不同用户会根据权限不同显示不同的内容,下面的修改操作也已经有文字说明,更换账号测试便知。</p>


<p>然后我们在实际项目中:不但要在页面上控制不同权限隐藏或将某些操作设置为不可用状态,还要在实际上控制那个操作背后的请求是真的不可以使用的。(例如:页面上的修改按钮已经灰化了,而我知道了修改按钮正常情况下点击会触发的请求,此时我直接模拟这个修改请求,应当是没有权限的才对,这样才算是真正的控制了权限。)</p>


<hr>


<p>附: <br>
<strong>Filter Chain定义说明</strong> <br>
1、一个URL可以配置多个Filter,使用逗号分隔 <br>
2、当设置多个过滤器时,全部验证通过,才视为通过 <br>
3、部分过滤器可指定参数,如perms,roles</p>


<p><strong>Shiro内置的FilterChain</strong></p>


<table>
<thead>
<tr>
  <th>Filter Name</th>
  <th>Class</th>
</tr>
</thead>
<tbody><tr>
  <td>anon</td>
  <td>org.apache.shiro.web.filter.authc.AnonymousFilter</td>
</tr>
<tr>
  <td>authc</td>
  <td>org.apache.shiro.web.filter.authc.FormAuthenticationFilter</td>
</tr>
<tr>
  <td>authcBasic</td>
  <td>org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter</td>
</tr>
<tr>
  <td>perms</td>
  <td>org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter</td>
</tr>
<tr>
  <td>port</td>
  <td>org.apache.shiro.web.filter.authz.PortFilter</td>
</tr>
<tr>
  <td>rest</td>
  <td>org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter</td>
</tr>
<tr>
  <td>roles</td>
  <td>org.apache.shiro.web.filter.authz.RolesAuthorizationFilter</td>
</tr>
<tr>
  <td>ssl</td>
  <td>org.apache.shiro.web.filter.authz.SslFilter</td>
</tr>
<tr>
  <td>user</td>
  <td>org.apache.shiro.web.filter.authc.UserFilter</td>
</tr>
</tbody></table></div>
        <script type="text/javascript">
            $(function () {
                $('pre.prettyprint code').each(function () {
                    var lines = $(this).text().split('\n').length;
                    var $numbering = $('<ul/>').addClass('pre-numbering').hide();
                    $(this).addClass('has-numbering').parent().append($numbering);
                    for (i = 1; i <= lines; i++) {
                        $numbering.append($('<li/>').text(i));
                    };
                    $numbering.fadeIn(1700);
                });
            });
        </script>
   
</div>








<!-- Baidu Button BEGIN -->








<div class="bdsharebuttonbox tracking-ad bdshare-button-style0-16" style="float: right;" data-mod="popu_172" data-bd-bind="1512724736302">
<a href="#" class="bds_more" data-cmd="more" style="background-position:0 0 !important; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png) !important" target="_blank"></a>
<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间" style="background-position:0 -52px !important" target="_blank"></a>
<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博" style="background-position:0 -104px !important" target="_blank"></a>
<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博" style="background-position:0 -260px !important" target="_blank"></a>
<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网" style="background-position:0 -208px !important" target="_blank"></a>
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信" style="background-position:0 -1612px !important" target="_blank"></a>
</div>
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script>
<!-- Baidu Button END -->


   


<!--172.16.140.13-->


<!-- Baidu Button BEGIN -->
<script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=1536434" src="http://bdimg.share.baidu.com/static/js/bds_s_v2.js?cdnversion=420202"></script>


<script type="text/javascript">
    document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
</script>
<!-- Baidu Button END -->






 




        <div id="digg" articleid="50520958">
            <dl id="btnDigg" class="digg digg_enable" onclick="btndigga();">
               
                 <dt>顶</dt>
                <dd>36</dd>
            </dl>
           
              
            <dl id="btnBury" class="digg digg_enable" onclick="btnburya();">
              
                  <dt>踩</dt>
                <dd>1</dd>               
            </dl>
            
        </div>
     <div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank">&nbsp;</a>   </div>
    <div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank">&nbsp;</a></div>
    <script type="text/javascript">
        function btndigga() {
            $(".tracking-ad[data-mod='popu_222'] a").click();
        }
        function btnburya() {
            $(".tracking-ad[data-mod='popu_223'] a").click();
        }
            </script>


   <ul class="article_next_prev">
                <li class="prev_article"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian']);location.href='http://blog.csdn.net/catoop/article/details/50508397';">上一篇</span><a href="http://blog.csdn.net/catoop/article/details/50508397" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian'])">Spring Boot JPA 连接数据库</a></li>
                <li class="next_article"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='http://blog.csdn.net/catoop/article/details/50530364';">下一篇</span><a href="http://blog.csdn.net/catoop/article/details/50530364" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">CAS 单点登陆</a></li>
    </ul>


    <div style="clear:both; height:10px;"></div>




            <div class="similar_article">
                    <h4></h4>
                    <div class="similar_c" style="margin:20px 0px 0px 0px">
                        <div class="similar_c_t">
                          &nbsp;&nbsp;相关文章推荐
                        </div>
                   
                        <div class="similar_wrap tracking-ad" data-mod="popu_36" style="max-height:250px">                       
                            <ul class="similar_list fl">    
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/ityouknow/article/details/73836159" title="springboot(十四):springboot整合shiro-登录认证和权限管理" strategy="BlogCommendFromBaidu_0" target="_blank">springboot(十四):springboot整合shiro-登录认证和权限管理</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/huiyiCourse/series_detail/73?utm_source=blog7" title="腾讯云容器服务架构实现介绍--董晓杰" strategy="undefined" target="_blank">腾讯云容器服务架构实现介绍--董晓杰</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/q975583865/article/details/78232811" title="springboot(十四):springboot整合shiro-登录认证和权限管理" strategy="BlogCommendFromBaidu_1" target="_blank">springboot(十四):springboot整合shiro-登录认证和权限管理</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/huiyiCourse/series_detail/74?utm_source=home7" title="微博热点事件背后的数据库运维心得--张冬洪" strategy="undefined" target="_blank">微博热点事件背后的数据库运维心得--张冬洪</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/xtiawxf/article/details/52571949" title="Spring Boot系列(十五) 安全框架Apache Shiro(一)基本功能" strategy="BlogCommendFromBaidu_2" target="_blank">Spring Boot系列(十五) 安全框架Apache Shiro(一)基本功能</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/course/detail/6134?utm_source=blog7" title="JDK9新特性--Array" strategy="undefined" target="_blank">JDK9新特性--Array</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/u012373815/article/details/57532292" title="springboot集成shiro 实现权限控制" strategy="BlogCommendFromBaidu_3" target="_blank">springboot集成shiro 实现权限控制</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/huiyiCourse/series_detail/73?utm_source=blog7" title="Kubernetes容器云平台实践--李志伟" strategy="undefined" target="_blank">Kubernetes容器云平台实践--李志伟</a>
                                   </li>
                            </ul>
                              <ul class="similar_list fr">      
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/lichongda/article/details/70673304" title="spring boot +mybatis+shiro" strategy="BlogCommendFromBaidu_4" target="_blank">spring boot +mybatis+shiro</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/course/detail/5226?utm_source=blog7" title="用Word2Vec处理自然语言" strategy="undefined" target="_blank">用Word2Vec处理自然语言</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/yincl123/article/details/64159939" title="springboot + shiro的配置" strategy="BlogCommendFromBaidu_5" target="_blank">springboot + shiro的配置</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://edu.csdn.net/course/detail/5116?utm_source=blog7" title="Java之优雅编程之道 " strategy="undefined" target="_blank">Java之优雅编程之道 </a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/malachi95/article/details/53337150" title="springboot使用shiro" strategy="BlogCommendFromBaidu_6" target="_blank">springboot使用shiro</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/fan510988896/article/details/55253791" title="springboot shiro 整合" strategy="BlogCommendFromBaidu_7" target="_blank">springboot shiro 整合</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/aqsunkai/article/details/69757017" title="SpringBoot学习:整合shiro(身份认证和权限认证),使用EhCache缓存" strategy="BlogCommendFromBaidu_8" target="_blank">SpringBoot学习:整合shiro(身份认证和权限认证),使用EhCache缓存</a>
                                   </li>
                                   <li>
                                       <em>•</em>
                                       <a href="http://blog.csdn.net/u014695188/article/details/52347372" title="Spring Boot Shiro权限管理" strategy="BlogCommendFromBaidu_9" target="_blank">Spring Boot Shiro权限管理</a>
                                   </li>
                            </ul>
                        </div>
                    </div>
                </div>   
      
</div>




<div id="suggest">


</div>
         <script language="javascript" type="text/javascript">     
             $(function(){
                 $.get("/catoop/svc/GetSuggestContent/50520958",function(data){
                     $("#suggest").html(data);
                 });     
             });             
         </script>  






            
                                    
            
                                    


        <!-- 广告位开始 -->
        <!-- 广告位结束 -->




<div class="comment_class">
    <div id="comment_title" class="panel_head">
        <span class="see_comment">查看评论</span><a name="comments"></a></div>
    <div id="comment_list"><dl class="comment_item comment_topic" id="comment_item_7362470"><dt class="comment_head" floor="37">37楼 <span class="user"><a class="username" href="/zuocheng217" target="_blank">三血狼</a> <span class="ptime">2017-11-23 15:13发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7362470" username="zuocheng217"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/zuocheng217" target="_blank"><img src="http://avatar.csdn.net/A/8/8/3_zuocheng217.jpg" width="40" height="40"></a></dd><dd class="comment_body">楼主有源码吗?求共享一份</dd></dl><dl class="comment_item comment_topic" id="comment_item_7322788"><dt class="comment_head" floor="36">36楼 <span class="user"><a class="username" href="/chris9421xy" target="_blank">半城煙沙</a> <span class="ptime">2017-11-07 10:54发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7322788" username="chris9421xy"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/chris9421xy" target="_blank"><img src="http://avatar.csdn.net/1/2/F/3_chris9421xy.jpg" width="40" height="40"></a></dd><dd class="comment_body">请问下 url 是怎么拦截的,比如我已经登录了,但是我没有访问某个列表的权限,但是我知道该url。</dd></dl><dl class="comment_item comment_topic" id="comment_item_7247573"><dt class="comment_head" floor="35">35楼 <span class="user"><a class="username" href="/zzjvslove" target="_blank">zzjvslove</a> <span class="ptime">2017-10-08 01:09发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="7247573" username="zzjvslove"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/zzjvslove" target="_blank"><img src="http://avatar.csdn.net/E/9/A/3_zzjvslove.jpg" width="40" height="40"></a></dd><dd class="comment_body">单哥啊,我集成JPA时总是出现无法导入javax.persistence.*包,实现仓库中是存在Entity等类。不知道如何解决?<br>因为无法集成JPA就集成了mybatis,返回JSON和JPA例子中的结果一致。<br>但是使用/login可以正常进入到登录页面,登录页面的图片也可以正常显示。在登录页面输入正确的用户和密码时,却显示如下错误,请问如何解决啊?<br>org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.<br><br>因还没有使用到查询数据库的权限,还只是把访问角色和权限写死的程序。就是无法进入/user页面。<br>QQ:172619619 谢谢啊</dd><dl class="comment_item comment_reply" id="comment_item_7247574"><dt class="comment_head" floor="35">Re: <span class="user"><a class="username" href="/zzjvslove" target="_blank">zzjvslove</a> <span class="ptime">2017-10-08 01:10发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="7247574" username="zzjvslove"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/zzjvslove" target="_blank"><img src="http://avatar.csdn.net/E/9/A/3_zzjvslove.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复zzjvslove:输入用户和密码之后,页面则是这个错误:<br>Whitelabel Error Page<br><br>This application has no explicit mapping for /error, so you are seeing this as a fallback.<br><br>Sun Oct 08 01:01:45 CST 2017<br>There was an unexpected error (type=Internal Server Error, status=500).<br>No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_7168412"><dt class="comment_head" floor="34">34楼 <span class="user"><a class="username" href="/lingyun870801" target="_blank">农村外出务工人员</a> <span class="ptime">2017-09-07 01:17发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7168412" username="lingyun870801"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/lingyun870801" target="_blank"><img src="http://avatar.csdn.net/3/F/E/3_lingyun870801.jpg" width="40" height="40"></a></dd><dd class="comment_body">我整合后导致事务不回滚,去掉shiro后正常。不知道你遇到这样的问题没有</dd></dl><dl class="comment_item comment_topic" id="comment_item_7156958"><dt class="comment_head" floor="33">33楼 <span class="user"><a class="username" href="/hzrabc" target="_blank">woyouele</a> <span class="ptime">2017-09-01 13:46发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7156958" username="hzrabc"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/hzrabc" target="_blank"><img src="http://avatar.csdn.net/4/7/B/3_hzrabc.jpg" width="40" height="40"></a></dd><dd class="comment_body">谢谢分享!</dd></dl><dl class="comment_item comment_topic" id="comment_item_7114696"><dt class="comment_head" floor="32">32楼 <span class="user"><a class="username" href="/m0_37675733" target="_blank">关公耍大刀</a> <span class="ptime">2017-08-22 10:05发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="7114696" username="m0_37675733"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/m0_37675733" target="_blank"><img src="http://avatar.csdn.net/5/7/B/3_m0_37675733.jpg" width="40" height="40"></a></dd><dd class="comment_body">很好</dd></dl><dl class="comment_item comment_topic" id="comment_item_7113467"><dt class="comment_head" floor="31">31楼 <span class="user"><a class="username" href="/bear_wong" target="_blank">bear_wong</a> <span class="ptime">2017-08-21 17:45发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7113467" username="bear_wong"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/bear_wong" target="_blank"><img src="http://avatar.csdn.net/F/F/A/3_bear_wong.jpg" width="40" height="40"></a></dd><dd class="comment_body">找了好几个版本的shrio的pom.xml,没找到EhCacheManager。楼主快贴pom.xml吧。。</dd><dl class="comment_item comment_reply" id="comment_item_7120384"><dt class="comment_head" floor="31">Re: <span class="user"><a class="username" href="/qq_34125349" target="_blank">勤能补拙1</a> <span class="ptime">2017-08-23 22:20发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7120384" username="qq_34125349"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_34125349" target="_blank"><img src="http://avatar.csdn.net/8/3/9/3_qq_34125349.jpg" width="40" height="40"></a></dd><dd class="comment_body">估计是他自己写的读取配置文件的方法没有上传,并不是shiro中封装的方法,代码中有几处这种是作者自己写的方法并没有上传</dd><dl class="comment_item comment_reply" id="comment_item_7170186"><dt class="comment_head" floor="1">Re: <span class="user"><a class="username" href="/ledzcl" target="_blank">ledzcl</a> <span class="ptime">2017-09-07 16:13发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7170186" username="ledzcl"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/ledzcl" target="_blank"><img src="http://avatar.csdn.net/3/3/E/3_ledzcl.jpg" width="40" height="40"></a></dd><dd class="comment_body"><div class="dp-highlighter bg_html"><div class="bar"><div class="tools"><b>[html]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><span data-mod="popu_168"> <a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><div style="position: absolute; left: 914px; top: 25291px; width: 18px; height: 18px; z-index: 99;"><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=18&amp;height=18" wmode="transparent"></div></span><span data-mod="popu_169"> <a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a></span><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">dependency</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="tag">&lt;</span><span class="tag-name">groupId</span><span class="tag">&gt;</span><span>org.apache.shiro</span><span class="tag">&lt;/</span><span class="tag-name">groupId</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">artifactId</span><span class="tag">&gt;</span><span>shiro-ehcache</span><span class="tag">&lt;/</span><span class="tag-name">artifactId</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="tag">&lt;</span><span class="tag-name">version</span><span class="tag">&gt;</span><span>1.2.4</span><span class="tag">&lt;/</span><span class="tag-name">version</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="tag">&lt;/</span><span class="tag-name">dependency</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><pre name="code2" class="html" style="display: none;">&lt;dependency&gt;
&lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;
&lt;artifactId&gt;shiro-ehcache&lt;/artifactId&gt;
&lt;version&gt;1.2.4&lt;/version&gt;
&lt;/dependency&gt;
</pre></dd></dl></dl></dl><dl class="comment_item comment_topic" id="comment_item_7103826"><dt class="comment_head" floor="30">30楼 <span class="user"><a class="username" href="/zhaobeibei123" target="_blank">j_Lawrencee</a> <span class="ptime">2017-08-17 16:49发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="7103826" username="zhaobeibei123"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/zhaobeibei123" target="_blank"><img src="http://avatar.csdn.net/1/D/1/3_zhaobeibei123.jpg" width="40" height="40"></a></dd><dd class="comment_body">看完了,没看明白,先收藏,继续看!感谢楼主分享!</dd></dl><dl class="comment_item comment_topic" id="comment_item_7042401"><dt class="comment_head" floor="29">29楼 <span class="user"><a class="username" href="/qq_38387420" target="_blank">qq_38387420</a> <span class="ptime">2017-07-31 15:41发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7042401" username="qq_38387420"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_38387420" target="_blank"><img src="http://avatar.csdn.net/3/B/5/3_qq_38387420.jpg" width="40" height="40"></a></dd><dd class="comment_body">请问源码地址有吗?qq179061434</dd><dl class="comment_item comment_reply" id="comment_item_7050091"><dt class="comment_head" floor="29">Re: <span class="user"><a class="username" href="/qq_36986446" target="_blank">D小H</a> <span class="ptime">2017-07-31 23:48发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7050091" username="qq_36986446"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_36986446" target="_blank"><img src="http://avatar.csdn.net/2/4/5/3_qq_36986446.jpg" width="40" height="40"></a></dd><dd class="comment_body">http://www.vxzsk.com/769.html,可以看看这个,更加详细</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_7040853"><dt class="comment_head" floor="28">28楼 <span class="user"><a class="username" href="/qq_35384853" target="_blank">邓盛余</a> <span class="ptime">2017-07-31 11:51发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="7040853" username="qq_35384853"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_35384853" target="_blank"><img src="http://avatar.csdn.net/F/E/F/3_qq_35384853.jpg" width="40" height="40"></a></dd><dd class="comment_body">求git地址</dd></dl><dl class="comment_item comment_topic" id="comment_item_7000971"><dt class="comment_head" floor="27">27楼 <span class="user"><a class="username" href="/wang_shuyu" target="_blank">wang_shuyu</a> <span class="ptime">2017-07-21 10:24发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="7000971" username="wang_shuyu"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/wang_shuyu" target="_blank"><img src="http://avatar.csdn.net/1/3/A/3_wang_shuyu.jpg" width="40" height="40"></a></dd><dd class="comment_body">求源码</dd></dl><dl class="comment_item comment_topic" id="comment_item_6992615"><dt class="comment_head" floor="26">26楼 <span class="user"><a class="username" href="/u011510502" target="_blank">jordandandan</a> <span class="ptime">2017-07-18 13:28发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6992615" username="u011510502"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u011510502" target="_blank"><img src="http://avatar.csdn.net/8/E/9/3_u011510502.jpg" width="40" height="40"></a></dd><dd class="comment_body">希望博主放源码到github上,版本不同会有很多坑的</dd></dl><dl class="comment_item comment_topic" id="comment_item_6938394"><dt class="comment_head" floor="25">25楼 <span class="user"><a class="username" href="/houtianle1012" target="_blank">houtianle1012</a> <span class="ptime">2017-06-27 14:08发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6938394" username="houtianle1012"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/houtianle1012" target="_blank"><img src="http://avatar.csdn.net/C/6/9/3_houtianle1012.jpg" width="40" height="40"></a></dd><dd class="comment_body">请问还有源码吗?</dd></dl><dl class="comment_item comment_topic" id="comment_item_6898931"><dt class="comment_head" floor="24">24楼 <span class="user"><a class="username" href="/abaloneking" target="_blank">theking888</a> <span class="ptime">2017-06-12 16:19发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6898931" username="abaloneking"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/abaloneking" target="_blank"><img src="http://avatar.csdn.net/B/B/9/3_abaloneking.jpg" width="40" height="40"></a></dd><dd class="comment_body">缓存起来的信息没有使用吧?</dd></dl><dl class="comment_item comment_topic" id="comment_item_6840160"><dt class="comment_head" floor="23">23楼 <span class="user"><a class="username" href="/qq_38824098" target="_blank">qq_38824098</a> <span class="ptime">2017-05-17 15:15发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6840160" username="qq_38824098"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_38824098" target="_blank"><img src="http://avatar.csdn.net/D/D/0/3_qq_38824098.jpg" width="40" height="40"></a></dd><dd class="comment_body">单哥,我的sprignboot能正常启动,但是打开不了jsp网页,路径是正确的,我不知道是怎么了,能不能帮我看看,不然我就要失业了</dd></dl><dl class="comment_item comment_topic" id="comment_item_6840145"><dt class="comment_head" floor="22">22楼 <span class="user"><a class="username" href="/qq_38824098" target="_blank">qq_38824098</a> <span class="ptime">2017-05-17 15:13发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6840145" username="qq_38824098"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_38824098" target="_blank"><img src="http://avatar.csdn.net/D/D/0/3_qq_38824098.jpg" width="40" height="40"></a></dd><dd class="comment_body">单哥,可以不可以帮我解决一个问题,就是我springboot正常启动了,但是 打开不了网页,我的路径是正确的</dd></dl><dl class="comment_item comment_topic" id="comment_item_6834962"><dt class="comment_head" floor="21">21楼 <span class="user"><a class="username" href="/wangqs927" target="_blank">嘎嘎嘎121</a> <span class="ptime">2017-05-15 13:59发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6834962" username="wangqs927"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/wangqs927" target="_blank"><img src="http://avatar.csdn.net/2/0/C/3_wangqs927.jpg" width="40" height="40"></a></dd><dd class="comment_body">谢谢分享,很实用</dd></dl><dl class="comment_item comment_topic" id="comment_item_6692847"><dt class="comment_head" floor="20">20楼 <span class="user"><a class="username" href="/rookie_s" target="_blank">rookie_s</a> <span class="ptime">2017-03-22 17:13发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6692847" username="rookie_s"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/rookie_s" target="_blank"><img src="http://avatar.csdn.net/1/3/8/3_rookie_s.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复rousuiguan9089:是哪个实体里面的set和get方法呀,本人小白,求指教。</dd><dl class="comment_item comment_reply" id="comment_item_6725569"><dt class="comment_head" floor="20">Re: <span class="user"><a class="username" href="/rousuiguan9089" target="_blank">rousuiguan9089</a> <span class="ptime">2017-04-01 13:42发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6725569" username="rousuiguan9089"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/rousuiguan9089" target="_blank"><img src="http://avatar.csdn.net/4/4/A/3_rousuiguan9089.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复rookie_s:pom 加上这个 <br>&lt;dependency&gt;<br>&lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;<br>&lt;artifactId&gt;shiro-spring&lt;/artifactId&gt;<br>&lt;version&gt;1.2.4&lt;/version&gt;<br>&lt;/dependency&gt;</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_6691041"><dt class="comment_head" floor="19">19楼 <span class="user"><a class="username" href="/chwnjianhui" target="_blank">chwnjianhui</a> <span class="ptime">2017-03-22 09:20发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6691041" username="chwnjianhui"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/chwnjianhui" target="_blank"><img src="http://avatar.csdn.net/0/A/5/3_chwnjianhui.jpg" width="40" height="40"></a></dd><dd class="comment_body">有源码吗  分享一下吧</dd></dl><dl class="comment_item comment_topic" id="comment_item_6688996"><dt class="comment_head" floor="18">18楼 <span class="user"><a class="username" href="/rousuiguan9089" target="_blank">rousuiguan9089</a> <span class="ptime">2017-03-21 13:26发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6688996" username="rousuiguan9089"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/rousuiguan9089" target="_blank"><img src="http://avatar.csdn.net/4/4/A/3_rousuiguan9089.jpg" width="40" height="40"></a></dd><dd class="comment_body">就这个 直接 输入 /user , 没登陆 为什么 会直接  调到 login,登陆后 ,才调用 /user 这个 controller ,前边那个是怎么实现的,没找到,望 知道的指点一下,感谢</dd></dl><dl class="comment_item comment_topic" id="comment_item_6660898"><dt class="comment_head" floor="17">17楼 <span class="user"><a class="username" href="/rousuiguan9089" target="_blank">rousuiguan9089</a> <span class="ptime">2017-03-09 16:20发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6660898" username="rousuiguan9089"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/rousuiguan9089" target="_blank"><img src="http://avatar.csdn.net/4/4/A/3_rousuiguan9089.jpg" width="40" height="40"></a></dd><dd class="comment_body">跑出来了....</dd></dl><dl class="comment_item comment_topic" id="comment_item_6629004"><dt class="comment_head" floor="16">16楼 <span class="user"><a class="username" href="/hewei_bj" target="_blank">hewei_bj</a> <span class="ptime">2017-02-27 15:56发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6629004" username="hewei_bj"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/hewei_bj" target="_blank"><img src="http://avatar.csdn.net/B/0/5/3_hewei_bj.jpg" width="40" height="40"></a></dd><dd class="comment_body">根本跑不起来<br><br>ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@34f5090e: startup date [Mon Feb 27 15:48:42 CST 2017]; root of context hierarchy<br><br>网上查了也跑不起来</dd></dl><dl class="comment_item comment_topic" id="comment_item_6622639"><dt class="comment_head" floor="15">15楼 <span class="user"><a class="username" href="/u012385432" target="_blank">DennisDing0201</a> <span class="ptime">2017-02-24 15:55发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6622639" username="u012385432"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u012385432" target="_blank"><img src="http://avatar.csdn.net/F/7/B/3_u012385432.jpg" width="40" height="40"></a></dd><dd class="comment_body">很好的教程。。。<br>亲测可行。</dd><dl class="comment_item comment_reply" id="comment_item_6629013"><dt class="comment_head" floor="15">Re: <span class="user"><a class="username" href="/hewei_bj" target="_blank">hewei_bj</a> <span class="ptime">2017-02-27 15:58发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6629013" username="hewei_bj"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/hewei_bj" target="_blank"><img src="http://avatar.csdn.net/B/0/5/3_hewei_bj.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复DennisDing0201:为什么我的不行</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_6546812"><dt class="comment_head" floor="14">14楼 <span class="user"><a class="username" href="/macle_zhou" target="_blank">macle_zhou</a> <span class="ptime">2017-01-11 13:01发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6546812" username="macle_zhou"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/macle_zhou" target="_blank"><img src="http://avatar.csdn.net/7/2/E/3_macle_zhou.jpg" width="40" height="40"></a></dd><dd class="comment_body">博主好,这个例子没有运行成功,求源代码,比较一下。谢谢了</dd></dl><dl class="comment_item comment_topic" id="comment_item_6530802"><dt class="comment_head" floor="13">13楼 <span class="user"><a class="username" href="/u011332983" target="_blank">青牛</a> <span class="ptime">2017-01-03 11:45发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6530802" username="u011332983"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u011332983" target="_blank"><img src="http://avatar.csdn.net/3/8/F/3_u011332983.jpg" width="40" height="40"></a></dd><dd class="comment_body">请问我在调用自己重写的shiroFilterFactoryBean的时候登陆报了 No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.怎么解决啊?</dd></dl><dl class="comment_item comment_topic" id="comment_item_6476024"><dt class="comment_head" floor="12">12楼 <span class="user"><a class="username" href="/yangjiegang8" target="_blank">肖木</a> <span class="ptime">2016-12-11 14:23发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6476024" username="yangjiegang8"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/yangjiegang8" target="_blank"><img src="http://avatar.csdn.net/9/A/2/3_yangjiegang8.jpg" width="40" height="40"></a></dd><dd class="comment_body">确实好文,正在学习,感谢分享。</dd></dl><dl class="comment_item comment_topic" id="comment_item_6412451"><dt class="comment_head" floor="11">11楼 <span class="user"><a class="username" href="/u013065874" target="_blank">yakamy</a> <span class="ptime">2016-11-16 13:35发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6412451" username="u013065874"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u013065874" target="_blank"><img src="http://avatar.csdn.net/C/B/9/3_u013065874.jpg" width="40" height="40"></a></dd><dd class="comment_body">之前有个项目是 jfinal+shiro  他用的是redis做shiro的缓存,我想改造成 spring boot + shiro 请问有没有相关的例子啊</dd></dl><dl class="comment_item comment_topic" id="comment_item_6273277"><dt class="comment_head" floor="10">10楼 <span class="user"><a class="username" href="/DDDD1CCCC2" target="_blank">AugustLees</a> <span class="ptime">2016-09-14 12:49发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6273277" username="DDDD1CCCC2"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/DDDD1CCCC2" target="_blank"><img src="http://avatar.csdn.net/F/8/0/3_dddd1cccc2.jpg" width="40" height="40"></a></dd><dd class="comment_body">你的git地址在哪里啊</dd></dl><dl class="comment_item comment_topic" id="comment_item_6263670"><dt class="comment_head" floor="9">9楼 <span class="user"><a class="username" href="/wu_nai2009" target="_blank">乐柏哥哥</a> <span class="ptime">2016-09-08 15:42发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6263670" username="wu_nai2009"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/wu_nai2009" target="_blank"><img src="http://avatar.csdn.net/3/7/9/3_wu_nai2009.jpg" width="40" height="40"></a></dd><dd class="comment_body">1. MShiroFilterFactoryBean  这个继承了ShiroFilterFactoryBean,却并没有被你配置进去!<br>2. 在ShiroConfiguration  配置dao实现无法从spring容器里获取,无法实现filterChainDefinitionMap从数据库加载</dd></dl><dl class="comment_item comment_topic" id="comment_item_6231824"><dt class="comment_head" floor="8">8楼 <span class="user"><a class="username" href="/u011147538" target="_blank">Mr_Zhang_ZD</a> <span class="ptime">2016-08-26 16:31发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6231824" username="u011147538"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u011147538" target="_blank"><img src="http://avatar.csdn.net/C/0/A/3_u011147538.jpg" width="40" height="40"></a></dd><dd class="comment_body">为什么启动你的项目 显示这个异常啊<br>Whitelabel Error Page<br><br>This application has no explicit mapping for /error, so you are seeing this as a fallback.<br><br>Fri Aug 26 16:26:27 GMT+08:00 2016<br>There was an unexpected error (type=Not Found, status=404).<br>No message available</dd><dl class="comment_item comment_reply" id="comment_item_6286512"><dt class="comment_head" floor="8">Re: <span class="user"><a class="username" href="/pengxing1010" target="_blank">pengxing1010</a> <span class="ptime">2016-09-23 14:23发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6286512" username="pengxing1010"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/pengxing1010" target="_blank"><img src="http://avatar.csdn.net/B/0/D/3_pengxing1010.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复Mr_Zhang_ZD:项目缺少jsp支持</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_6219681"><dt class="comment_head" floor="7">7楼 <span class="user"><a class="username" href="/xtito521125" target="_blank">一介农民</a> <span class="ptime">2016-08-19 17:14发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6219681" username="xtito521125"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/xtito521125" target="_blank"><img src="http://avatar.csdn.net/B/5/B/3_xtito521125.jpg" width="40" height="40"></a></dd><dd class="comment_body">大神求认识</dd></dl><dl class="comment_item comment_topic" id="comment_item_6202861"><dt class="comment_head" floor="6">6楼 <span class="user"><a class="username" href="/YangmuMoon" target="_blank">YangmuMoon</a> <span class="ptime">2016-08-10 00:24发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6202861" username="YangmuMoon"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/YangmuMoon" target="_blank"><img src="http://avatar.csdn.net/B/4/2/3_yangmumoon.jpg" width="40" height="40"></a></dd><dd class="comment_body"></dd></dl><dl class="comment_item comment_topic" id="comment_item_6167010"><dt class="comment_head" floor="5">5楼 <span class="user"><a class="username" href="/David1025" target="_blank">David1025</a> <span class="ptime">2016-08-01 10:26发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display:none;" commentid="6167010" username="David1025"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/David1025" target="_blank"><img src="http://avatar.csdn.net/4/D/3/3_david1025.jpg" width="40" height="40"></a></dd><dd class="comment_body">楼主可否写一个继承Spring security的例子,用数据库管理资源的</dd></dl><dl class="comment_item comment_topic" id="comment_item_5980426"><dt class="comment_head" floor="4">4楼 <span class="user"><a class="username" href="/belizer" target="_blank">belizer</a> <span class="ptime">2016-04-12 17:27发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="5980426" username="belizer"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/belizer" target="_blank"><img src="http://avatar.csdn.net/B/9/1/3_belizer.jpg" width="40" height="40"></a></dd><dd class="comment_body">希望下次的案例能是复制都能运行的。</dd><dl class="comment_item comment_reply" id="comment_item_6215957"><dt class="comment_head" floor="4">Re: <span class="user"><a class="username" href="/u012854426" target="_blank">明天110</a> <span class="ptime">2016-08-17 17:53发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6215957" username="u012854426"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/u012854426" target="_blank"><img src="http://avatar.csdn.net/5/4/4/3_u012854426.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复belizer:要求太高了</dd></dl></dl><dl class="comment_item comment_topic" id="comment_item_5966897"><dt class="comment_head" floor="3">3楼 <span class="user"><a class="username" href="/Cheers_" target="_blank">Cheers_</a> <span class="ptime">2016-04-01 10:39发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="5966897" username="Cheers_"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/Cheers_" target="_blank"><img src="http://avatar.csdn.net/5/6/1/3_cheers_.jpg" width="40" height="40"></a></dd><dd class="comment_body">为什么我在ShiroRealmImpl类(自定义的shrio realm)中 加载不了实体,比如那个 userDao,会提示空指针异常。我也试过了在ShiroConfiguration(配置类)里面实现ApplicationContextAware,通过override  setApplicationContext方法来提前加载,但是一样报错:Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.NullPointerException<br><br>我知道是因为spring-mvc里面配置的bean比shiro晚加载,但是因为spring-boot是自动扫描的(@ComponentScan  @EnableAutoConfiguration)所以我不知道怎么弄 求指教</dd><dl class="comment_item comment_reply" id="comment_item_6618192"><dt class="comment_head" floor="3">Re: <span class="user"><a class="username" href="/ningbw2000" target="_blank">ningbw2000</a> <span class="ptime">2017-02-22 15:53发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6618192" username="ningbw2000"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/ningbw2000" target="_blank"><img src="http://avatar.csdn.net/D/F/A/3_ningbw2000.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复Cheers_:我也遇到了这个问题,你是怎么解决的</dd></dl><dl class="comment_item comment_reply" id="comment_item_5967298"><dt class="comment_head" floor="3">Re: <span class="user"><a class="username" href="/Cheers_" target="_blank">Cheers_</a> <span class="ptime">2016-04-01 15:15发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="5967298" username="Cheers_"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/Cheers_" target="_blank"><img src="http://avatar.csdn.net/5/6/1/3_cheers_.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复Cheers_:我自己解决了。。和我写的另一个配置有冲突</dd><dl class="comment_item comment_reply" id="comment_item_6817784"><dt class="comment_head" floor="2">Re: <span class="user"><a class="username" href="/qq_35914097" target="_blank">qq_35914097</a> <span class="ptime">2017-05-09 14:22发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="6817784" username="qq_35914097"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/qq_35914097" target="_blank"><img src="http://avatar.csdn.net/9/E/3/3_qq_35914097.jpg" width="40" height="40"></a></dd><dd class="comment_body">回复Cheers_:兄弟 怎么解决的? 我也遇到了这个问题 求助啊</dd></dl></dl></dl><dl class="comment_item comment_topic" id="comment_item_5851001"><dt class="comment_head" floor="2">2楼 <span class="user"><a class="username" href="/songzt_" target="_blank">songzt_</a> <span class="ptime">2016-01-22 17:26发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="5851001" username="songzt_"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/songzt_" target="_blank"><img src="http://avatar.csdn.net/3/A/5/3_songzt_.jpg" width="40" height="40"></a></dd><dd class="comment_body">现在是已经过时了吗?</dd></dl><dl class="comment_item comment_topic" id="comment_item_5844098"><dt class="comment_head" floor="1">1楼 <span class="user"><a class="username" href="/songzt_" target="_blank">songzt_</a> <span class="ptime">2016-01-16 15:30发表</span>  <a href="#reply" class="cmt_btn reply" title="回复">[回复]</a> <span class="comment_manage" style="display: none;" commentid="5844098" username="songzt_"> <a href="#quote" class="cmt_btn quote" title="引用">[引用]</a> <a href="#report" class="cmt_btn report" title="举报">[举报]</a></span></span></dt><dd class="comment_userface"><a href="/songzt_" target="_blank"><img src="http://avatar.csdn.net/3/A/5/3_songzt_.jpg" width="40" height="40"></a></dd><dd class="comment_body">楼主快快更新一下集成mybatis的吧,这个完全看不懂啊,坐等更新…………</dd></dl><div class="clear"></div></div>
    <div id="comment_bar" style="display: none;">
    </div>
    <div id="comment_form"><a name="commentbox"></a><a name="reply"></a><a name="quote"></a><form action="/catoop/comment/submit?id=50520958" method="post" onsubmit="return subform(this);"><div class="commentform"><div class="panel_head">发表评论</div><ul><li class="left">用 户 名:</li><li class="right">pingchangxin2017</li></ul><ul><li class="left">评论内容:</li><li class="right" style="position:relative;"><div id="ubbtools"><a href="#insertcode" code="code"><img src="http://static.blog.csdn.net/images/ubb/code.gif" border="0" alt="插入代码" title="插入代码"></a></div><div id="lang_list" style="position: absolute; top: 28px; left: 0px; display: none;"><a class="long_name" href="#html">HTML/XML</a><a class="long_name" href="#objc">objective-c</a><a class="zhong_name" href="#delphi">Delphi</a><a class="zhong_name" href="#ruby">Ruby</a><a href="#php">PHP</a><a class="duan_name" href="#csharp">C#</a><a style=" border-right: none;" class="duan_name" href="#cpp">C++</a><a style=" border-bottom:none;" class="long_name" href="#javascript">JavaScript</a><a style=" border-bottom:none;" class="long_name" href="#vb">Visual Basic</a><a style=" border-bottom:none;" class="zhong_name" href="#python">Python</a><a style=" border-bottom:none;" class="zhong_name" href="#java">Java</a><a style="border-bottom:none;" class="duan_name" href="#css">CSS</a><a style="border-bottom:none;" class="duan_name" href="#sql">SQL</a><a style="border:none;" class="duan_name" href="#plain">其它</a></div><textarea class="comment_content" name="comment_content" id="comment_content" style="width: 400px; height: 200px;"></textarea></li></ul><ul><input type="hidden" id="comment_replyId" name="comment_replyId"><input type="hidden" id="comment_userId" name="comment_userId" value="521203"><input type="hidden" id="commentId" name="commentId" value=""><input type="submit" class="comment_btn" value="提交">&nbsp;&nbsp;<span id="tip_comment" style="color: Red; display: none;"></span></ul></div></form></div>
    <div class="announce">
        * 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场<a name="reply"></a><a name="quote"></a></div>
</div>


<script type="text/javascript">
    var fileName = '50520958';
    var commentscount = 59;
    var islock = false
</script>


    <div id="ad_bot">
    </div>
<div id="report_dialog">
</div>


<div id="d-top" style="bottom:60px;">


        <a id="quick-reply" class="btn btn-top q-reply" title="快速回复" style="display:none;">
            <img src="http://static.blog.csdn.net/images/blog-icon-reply.png" alt="快速回复">
        </a>    
    <a id="d-top-a" class="btn btn-top backtop" style="display: none;" title="返回顶部" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_huidaodingbu'])">         
         <img src="http://static.blog.csdn.net/images/top.png" alt="TOP">
    </a>
</div>
<script type="text/javascript">
    $(function ()
    {
        $("#ad_frm_0").height("90px");
        
        setTimeout(function(){
            $("#ad_frm_2").height("200px");
        },1000);    
    });
  
</script>
<style type="text/css">
    .tag_list
    {
        background: none repeat scroll 0 0 #FFFFFF;
        border: 1px solid #D7CBC1;
        color: #000000;
        font-size: 12px;
        line-height: 20px;
        list-style: none outside none;
        margin: 10px 2% 0 1%;
        padding: 1px;
    }
    .tag_list h5
    {
        background: none repeat scroll 0 0 #E0DBD3;
        color: #47381C;
        font-size: 12px;
        height: 24px;
        line-height: 24px;
        padding: 0 5px;
        margin: 0;
    }
    .tag_list h5 a
    {
        color: #47381C;
    }
    .classify
    {
        margin: 10px 0;
        padding: 4px 12px 8px;
    }
    .classify a
    {
        margin-right: 20px;
        white-space: nowrap;
    }
</style>










<div id="pop_win" style="display:none ;position: absolute; z-index: 10000; border: 1px solid rgb(220, 220, 220); top: 222.5px; left: 630px; opacity: 1; background: none 0px 0px repeat scroll rgb(255, 255, 255);">
    
</div>
<div id="popup_mask"></div>
<style>
    #popup_mask
    {
        position: absolute;
        width: 100%;
        height: 100%;
        background: #000;
        z-index: 9999;
        left: 0px;
        top: 0px;
        opacity: 0.3;
        filter: alpha(opacity=30);
        display: none;
    }


</style>








<script type="text/javascript">
    $(function(){        
        
        setTimeout(function(){
            $(".comment_body:contains('回复')").each(function(index,item){
                var u=$(this).text().split(':')[0].toString().replace("回复","")
                var thisComment=$(this);
                if(u)
                {
                    $.getJSON("https://passport.csdn.net/get/nick?callback=?", {users: u}, function(a) {
                        if(a!=null&&a.data!=null&&a.data.length>0)
                        {
                            nick=a.data[0].n; 
                            if(u!=nick)
                            {
                                thisComment.text(thisComment.text().replace(u,nick));  
                            }
                        }       
                    });  
                }
            });         


        },200);  


        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },5000);


        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },10000);


        setTimeout(function(){
            $(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); })
        },15000);
        
        setTimeout(function(){
            $("a img[src='http://js.tongji.linezing.com/stats.gif']").parent().css({"position":"absolute","left":"50%"});
        },300);
    });


    function loginbox(){
        var $logpop=$("#pop_win");
        $logpop.html('<iframe src="https://passport.csdn.net/account/loginbox?service=http://static.blog.csdn.net/callback.htm" frameborder="0" height="600" width="400" scrolling="no"></iframe>');


        $('#popup_mask').css({
            opacity: 0.5,
            width: $( document ).width() + 'px',
            height:  $( document ).height() + 'px'
        });
        $('#popup_mask').css("display","block");
 
        $logpop.css( {
            top: ($( window ).height() - $logpop.height())/ 2  + $( window 
       ).scrollTop() + 'px',
            left:($( window ).width() - $logpop.width())/ 2
        } );
 
        setTimeout( function () {
            $logpop.show();
            $logpop.css( {
                opacity: 1
            } );
        }, 200 );
 
        $('#popup_mask').unbind("click");
        $('#popup_mask').bind("click", function(){
            $('#popup_mask').hide();
            var $clopop = $("#pop_win");
            $("#common_ask_div_sc").css("display","none");
            $clopop.css( {
                opacity: 0
            } );
            setTimeout( function () {
                $clopop.hide();
            }, 350 );
            return false;
        });
    }   


    var articletitle='Spring Boot Shiro 权限管理';


</script>




















                        <div class="clear">
                        </div>
                    </div>                   
                
            </div>
                   
           <div id="side">
               
    <div class="side">
<div id="panel_Profile" class="panel">
<ul class="panel_head"><span>个人资料</span></ul>
<ul class="panel_body profile">
<div id="blog_userface">
    <a href="http://my.csdn.net/catoop" target="_blank">
    <img src="http://avatar.csdn.net/3/0/1/1_catoop.jpg" title="访问我的空间" style="max-width:90%">
    </a>
    <br>
    <span><a href="http://my.csdn.net/catoop" class="user_name" target="_blank">catoop</a></span>
</div>
<div class="interact">


    <a href="javascript:void(0);" class="attent" id="span_add_follow" title="[加关注]"></a>


 <a href="javascript:void(0);" class="letter" title="[发私信]" onclick="window.open('http://msg.csdn.net/letters/model?receiver=catoop','_blank','height=350,width=700');_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_sixin'])"></a>  
</div>
<div id="blog_medal">
                       <div class="ico_expert" onclick="javascript:location='http://blog.csdn.net/experts/rule.html'" title="CSDN认证专家" style="cursor:pointer;width:60px;height:60px;background:url('http://c.csdnimg.cn/jifen/images/xunzhang/xunzhang/bokezhuanjiamiddle.png') no-repeat"></div>
                <div id="bms_box">
                                            <a target="_blank">
                                                    <img src="http://c.csdnimg.cn/jifen/images/xunzhang/xunzhang/zhuanlandaren.png" onmouseover="m_over_m(this,2)" onmouseout="m_out_m()" alt="2">
                                            </a>
                                            <a target="_blank">
                                                    <img src="http://c.csdnimg.cn/jifen/images/xunzhang/xunzhang/chizhiyiheng.png" onmouseover="m_over_m(this,4)" onmouseout="m_out_m()" alt="3">
                                            </a>
               </div>
</div>
<ul id="blog_rank">
    <li>访问:<span>3947506次</span></li>
    <li>积分:<span>23254</span> </li>    
    <li>等级: <span style="position:relative;display:inline-block;z-index:1">
            <img src="http://c.csdnimg.cn/jifen/images/xunzhang/jianzhang/blog7.png" alt="" style="vertical-align: middle;" id="leveImg">
            <div id="smallTittle" style=" position: absolute;  left: -24px;  top: 25px;  text-align: center;  width: 101px;  height: 32px;  background-color: #fff;  line-height: 32px;  border: 2px #DDDDDD solid;  box-shadow: 0px 2px 2px rgba (0,0,0,0.1);  display: none;   z-index: 999;">
            <div style="left: 42%;  top: -8px;  position: absolute;  width: 0;  height: 0;  border-left: 10px solid transparent;  border-right: 10px solid transparent;  border-bottom: 8px solid #EAEAEA;"></div>
            积分:23254 </div>
        </span>  </li>
    <li>排名:<span>第334名</span></li>
</ul>
<ul id="blog_statistics">
    <li>原创:<span>267篇</span></li>
    <li>转载:<span>40篇</span></li>
    <li>译文:<span>10篇</span></li>
    <li>评论:<span>1008条</span></li>
</ul>
</ul>
</div>




<div class="panel" id="panel_Search">
    <ul class="panel_head"><span>文章搜索</span></ul>
    <ul class="panel_body">
        <form id="frmSearch" action="http://so.csdn.net/search" class="form_search csdn-tracking-statistics" target="_blank" data-mod="popu_306">
        <span><input id="inputSearch" type="text" class="blogsearch" title="请输入关键字"></span>
        <input id="btnSubmit" type="button" value="搜索" title="search in blog">
        <input type="hidden" name="q" id="inputQ">
        <input type="hidden" name="t" value="blog">
        <a id="btnSearchBlog" target="_blank"></a>
        </form>
    </ul>
</div>


<script type="text/javascript">


   
    $(function () {
        $("#btnSubmit").unbind("click");
        $("#btnSubmit").click(function () {           
            search();
        });


        $("#frmSearch").submit(function () {           
            search();
            return false;
        });


        function search()
        {
            if ($("#inputSearch").val() == "") {               
                alert("请录入搜索关键词!");                         
                return false;
            }
            //var url = "http://so.csdn.net/so/search/s.do?q=" + encodeURIComponent($("#inputSearch").val()) + "&u=" + username + "&t=blog";           
            var url = "https://www.baidu.com/s?wd=" + encodeURIComponent($("#inputSearch").val()) + "%20site%3Ablog.csdn.net"
            window.location.href = url;
        }   
    });
</script><div id="panel_Category" class="panel">
    <ul class="panel_head"><span>博客专栏</span></ul>
    <ul class="panel_body" id="sp_column">
    <table cellpadding="0" cellspacing="0"><tbody><tr>
    <td style="padding:10px 10px 0 0;">
    <a href="http://blog.csdn.net/column/details/spring-boot.html" target="_blank"><img src="http://img.blog.csdn.net/20160127143219936" style="width:75px;height:75px;"></a>
    </td>
    <td style="padding:10px 0; vertical-align:top;">
    <a href="http://blog.csdn.net/column/details/spring-boot.html" target="_blank">Spring Boot 学习</a>
    <p>文章:28篇</p>
    <span>阅读:1179570</span>
    </td>
    </tr></tbody></table>
    </ul>
</div><div id="panel_Category" class="panel">
<ul class="panel_head"><span>文章分类</span></ul>
<ul class="panel_body">    
                 <li>
                    <a href="/catoop/article/category/1133741" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Android</a><span>(63)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1135096" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">应用部署</a><span>(26)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1143017" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">其他中间件</a><span>(24)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1151711" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Linux</a><span>(38)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1153789" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">观点论</a><span>(3)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1155645" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">开发工具</a><span>(6)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1157507" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Ant</a><span>(8)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1253513" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">软件测试</a><span>(2)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1268853" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">数据库</a><span>(17)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1305587" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">线程</a><span>(8)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/1510443" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Java开发</a><span>(35)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/2017705" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">JavaScript</a><span>(8)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/5757035" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">ApacheServer</a><span>(5)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/5789635" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Spring</a><span>(43)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/5818477" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Maven</a><span>(8)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6050199" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Gradle</a><span>(2)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6056655" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">未分类</a><span>(0)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6872689" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">其他</a><span>(2)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6872701" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">插件</a><span>(1)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6914723" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">日志</a><span>(1)</span>
                </li>
                 <li>
                    <a href="/catoop/article/category/6946874" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">硬件</a><span>(1)</span>
                </li>
</ul>
</div><div id="panel_Archive" class="panel">
<ul class="panel_head"><span>文章存档</span></ul>
<ul class="panel_body">
<div id="archive_list"><li><a href="/catoop/article/month/2017/05">2017年05月</a><span>(10)</span></li><li><a href="/catoop/article/month/2017/04">2017年04月</a><span>(11)</span></li><li><a href="/catoop/article/month/2017/03">2017年03月</a><span>(6)</span></li><li><a href="/catoop/article/month/2017/02">2017年02月</a><span>(2)</span></li><li><a href="/catoop/article/month/2017/01">2017年01月</a><span>(1)</span></li><span class="hidelist" style="display:none;"><li><a href="/catoop/article/month/2016/12">2016年12月</a><span>(1)</span></li><li><a href="/catoop/article/month/2016/11">2016年11月</a><span>(1)</span></li><li><a href="/catoop/article/month/2016/09">2016年09月</a><span>(2)</span></li><li><a href="/catoop/article/month/2016/04">2016年04月</a><span>(10)</span></li><li><a href="/catoop/article/month/2016/03">2016年03月</a><span>(12)</span></li><li><a href="/catoop/article/month/2016/02">2016年02月</a><span>(10)</span></li><li><a href="/catoop/article/month/2016/01">2016年01月</a><span>(25)</span></li><li><a href="/catoop/article/month/2015/12">2015年12月</a><span>(17)</span></li><li><a href="/catoop/article/month/2015/11">2015年11月</a><span>(17)</span></li><li><a href="/catoop/article/month/2015/10">2015年10月</a><span>(10)</span></li><li><a href="/catoop/article/month/2015/09">2015年09月</a><span>(13)</span></li><li><a href="/catoop/article/month/2015/08">2015年08月</a><span>(21)</span></li><li><a href="/catoop/article/month/2015/07">2015年07月</a><span>(12)</span></li><li><a href="/catoop/article/month/2015/06">2015年06月</a><span>(5)</span></li><li><a href="/catoop/article/month/2015/05">2015年05月</a><span>(1)</span></li><li><a href="/catoop/article/month/2015/01">2015年01月</a><span>(9)</span></li><li><a href="/catoop/article/month/2014/12">2014年12月</a><span>(4)</span></li><li><a href="/catoop/article/month/2014/11">2014年11月</a><span>(6)</span></li><li><a href="/catoop/article/month/2014/10">2014年10月</a><span>(8)</span></li><li><a href="/catoop/article/month/2014/09">2014年09月</a><span>(2)</span></li><li><a href="/catoop/article/month/2014/08">2014年08月</a><span>(3)</span></li><li><a href="/catoop/article/month/2014/07">2014年07月</a><span>(2)</span></li><li><a href="/catoop/article/month/2014/06">2014年06月</a><span>(5)</span></li><li><a href="/catoop/article/month/2014/05">2014年05月</a><span>(2)</span></li><li><a href="/catoop/article/month/2014/04">2014年04月</a><span>(6)</span></li><li><a href="/catoop/article/month/2014/03">2014年03月</a><span>(4)</span></li><li><a href="/catoop/article/month/2013/11">2013年11月</a><span>(1)</span></li><li><a href="/catoop/article/month/2013/07">2013年07月</a><span>(1)</span></li><li><a href="/catoop/article/month/2013/01">2013年01月</a><span>(1)</span></li><li><a href="/catoop/article/month/2012/12">2012年12月</a><span>(12)</span></li><li><a href="/catoop/article/month/2012/10">2012年10月</a><span>(3)</span></li><li><a href="/catoop/article/month/2012/09">2012年09月</a><span>(2)</span></li><li><a href="/catoop/article/month/2012/08">2012年08月</a><span>(2)</span></li><li><a href="/catoop/article/month/2012/07">2012年07月</a><span>(1)</span></li><li><a href="/catoop/article/month/2012/05">2012年05月</a><span>(18)</span></li><li><a href="/catoop/article/month/2012/04">2012年04月</a><span>(7)</span></li><li><a href="/catoop/article/month/2012/03">2012年03月</a><span>(3)</span></li></span><div id="archive_list_button" class="list_closed">展开</div></div>
</ul>
</div>
<div id="hotarticls" class="panel tracking-ad" data-mod="popu_340">
<ul class="panel_head">
    <span>       
阅读排行    </span>
</ul>


<ul class="panel_body itemlist">
<li>
<a href="/catoop/article/details/50588851" title="Spring Boot 部署与服务配置" target="_blank">Spring Boot 部署与服务配置</a><span>(111454)</span>
</li>
<li>
<a href="/catoop/article/details/40188775" title="httppost 302 错误,HttpPost、HttpGet关于URL重定向区别" target="_blank">httppost 302 错误,HttpPost、HttpGet关于URL重定向区别</a><span>(101035)</span>
</li>
<li>
<a href="/catoop/article/details/39993075" title="安卓首页图片轮播效果(淘宝、京东首页广告效果)" target="_blank">安卓首页图片轮播效果(淘宝、京东首页广告效果)</a><span>(90929)</span>
</li>
<li>
<a href="/catoop/article/details/50520958" title="Spring Boot Shiro 权限管理" target="_blank">Spring Boot Shiro 权限管理</a><span>(84105)</span>
</li>
<li>
<a href="/catoop/article/details/7938061" title="修改Tomcat内存大小" target="_blank">修改Tomcat内存大小</a><span>(81535)</span>
</li>
<li>
<a href="/catoop/article/details/41821395" title="Linux配置定时,使用 crontab -e 与 直接编辑 /etc/crontab 的区别" target="_blank">Linux配置定时,使用 crontab -e 与 直接编辑 /etc/crontab 的区别</a><span>(78825)</span>
</li>
<li>
<a href="/catoop/article/details/50501706" title="Spring Boot 静态资源处理" target="_blank">Spring Boot 静态资源处理</a><span>(75620)</span>
</li>
<li>
<a href="/catoop/article/details/50595702" title="Spring Boot 事务的使用" target="_blank">Spring Boot 事务的使用</a><span>(74153)</span>
</li>
<li>
<a href="/catoop/article/details/50507516" title="Spring Boot JDBC 连接数据库" target="_blank">Spring Boot JDBC 连接数据库</a><span>(68338)</span>
</li>
<li>
<a href="/catoop/article/details/50501696" title="Spring Boot 拦截器" target="_blank">Spring Boot 拦截器</a><span>(66615)</span>
</li>
</ul>
</div>
<div id="hotarticls2" class="panel tracking-ad" data-mod="popu_341">
<ul class="panel_head"><span>评论排行</span></ul>
<ul class="panel_body itemlist">
<li>
<a href="/catoop/article/details/39993075" title="安卓首页图片轮播效果(淘宝、京东首页广告效果)" target="_blank">安卓首页图片轮播效果(淘宝、京东首页广告效果)</a><span>(71)</span>
</li>
<li>
<a href="/catoop/article/details/50520958" title="Spring Boot Shiro 权限管理" target="_blank">Spring Boot Shiro 权限管理</a><span>(59)</span>
</li>
<li>
<a href="/catoop/article/details/50501676" title="Spring Boot Controller" target="_blank">Spring Boot Controller</a><span>(40)</span>
</li>
<li>
<a href="/catoop/article/details/50575038" title="Spring Boot 动态数据源(多数据源自动切换)" target="_blank">Spring Boot 动态数据源(多数据源自动切换)</a><span>(36)</span>
</li>
<li>
<a href="/catoop/article/details/50595702" title="Spring Boot 事务的使用" target="_blank">Spring Boot 事务的使用</a><span>(27)</span>
</li>
<li>
<a href="/catoop/article/details/50553714" title="Spring Boot MyBatis 连接数据库" target="_blank">Spring Boot MyBatis 连接数据库</a><span>(27)</span>
</li>
<li>
<a href="/catoop/article/details/50501688" title="Spring Boot 过滤器、监听器" target="_blank">Spring Boot 过滤器、监听器</a><span>(26)</span>
</li>
<li>
<a href="/catoop/article/details/50501706" title="Spring Boot 静态资源处理" target="_blank">Spring Boot 静态资源处理</a><span>(22)</span>
</li>
<li>
<a href="/catoop/article/details/50534006" title="Spring Boot 集成Shiro和CAS" target="_blank">Spring Boot 集成Shiro和CAS</a><span>(22)</span>
</li>
<li>
<a href="/catoop/article/details/50501664" title="Spring Boot 入门" target="_blank">Spring Boot 入门</a><span>(20)</span>
</li>
</ul>
</div>
<div id="homepageArticles" class="panel tracking-ad" data-mod="popu_4">
<ul class="panel_head"><span>推荐文章</span></ul>
<ul class="panel_body" id="ad_commend">
<ul>
<li>
<a href="http://blog.csdn.net/csdnproduct/article/details/78647961" target="_blank">* 【2017年11月27日】CSDN博客更新周报</a></li>
<br>
<li>
<a href="http://blog.csdn.net/blogdevteam/article/details/78287539" target="_blank">* 【CSDN】邀请您来GitChat赚钱啦!</a></li>
<br>
<li>
<a href="http://blog.csdn.net/blogdevteam/article/details/78625380" target="_blank">* 【GitChat】精选——JavaScript进阶指南</a></li>
<br>


<li>
<a href="http://blog.csdn.net/gitchat/article/details/78546894" target="_blank">* 改做人工智能之前,90%的人都没能给自己定位</a></li>
<br>
<li>
<a href="http://blog.csdn.net/gitchat/article/details/78546894" target="_blank">*  TensorFlow 人脸识别网络与对抗网络搭建</a></li>
<br>
<li>
<a href="http://blog.csdn.net/gitchat/article/details/78557241" target="_blank">*  Vue 移动端项目生产环境优化</a></li>
<br>
<li>
<a href="http://blog.csdn.net/gitchat/article/details/78546898" target="_blank">* 面试必考的计算机网络知识点梳理</a></li>


</ul></ul>
</div>




<div id="newcomments" class="panel">
<ul class="panel_head"><span>最新评论</span></ul>
<ul class="panel_body itemlist">
    <li>
   
         <a href="/catoop/article/details/50668896#comments">Spring Boot 集成Swagger</a>
    <p style="margin:0px;"><a href="/Mr__forget" class="user_name">Mr__forget</a>:
@hoochiang:过滤器?要怎么配置吗?
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/63257702#comments">Shiro报错No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.</a>
    <p style="margin:0px;"><a href="/wang974425633" class="user_name">wang974425633</a>:
lihai
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501676#comments">Spring Boot Controller</a>
    <p style="margin:0px;"><a href="/weixin_40877095" class="user_name">weixin_40877095</a>:
我用的是idea  运行不出来呀  怎么回事  不明白
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/51278675#comments">SpringMVC 使用验证框架 Bean Validation(上)</a>
    <p style="margin:0px;"><a href="/qq1623299667" class="user_name">海南小石</a>:
没有目录结构图,完全写不出来 。希望有个项目贴图和github代码之类
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501714#comments">Spring Boot 日志记录 SLF4J</a>
    <p style="margin:0px;"><a href="/sinat_24761867" class="user_name">思意</a>:
请教一下,springboot使用logback如何做日志持久化。将日志保存到指定的数据库表?谢谢!
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501688#comments">Spring Boot 过滤器、监听器</a>
    <p style="margin:0px;"><a href="/qq1623299667" class="user_name">海南小石</a>:
拦截器和过滤器有什么区别
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50575038#comments">Spring Boot 动态数据源(多数据源自动切换)</a>
    <p style="margin:0px;"><a href="/StudyCaiai" class="user_name">太极野兽</a>:
你好 ! 请问在什么地方配置 mybatis 的xml包扫描   如果是bean加载格式的话 要怎么...
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501686#comments">Spring Boot Servlet</a>
    <p style="margin:0px;"><a href="/qq1623299667" class="user_name">海南小石</a>:
博主我想请问下,我们都有requestmapping为什么需要servlet呢?
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501686#comments">Spring Boot Controller</a>
    <p style="margin:0px;"><a href="/qq1623299667" class="user_name">海南小石</a>:
@Amayadream:你的项目不是新建的把,spring.mvc.view.prefix=/WEB...
    </p>
    </li>
    <li>
   
         <a href="/catoop/article/details/50501686#comments">Spring Boot Controller</a>
    <p style="margin:0px;"><a href="/qq1623299667" class="user_name">海南小石</a>:
@cs408:我的改回jar也可以,可能是springboot做了处理吧。在以前tomcat里面都是...
    </p>
    </li>
</ul>
</div>
    </div>
    <div class="clear">
    </div>




           </div>   
            <div class="clear">
            </div>
        </div>


        
















    <script type="text/javascript" src="http://passport.csdn.net/content/loginbox/login.js"></script>
<script type="text/javascript">
    $(function () {
        function __get_code_toolbar(snippet_id) {
            return $("<span class='tracking-ad' data-mod='popu_167'><a href='https://code.csdn.net/snippets/"
                    + snippet_id
                    + "' target='_blank' title='在CODE上查看代码片'  style='text-indent:0;'><img src='https://code.csdn.net/assets/CODE_ico.png' width=12 height=12 alt='在CODE上查看代码片' style='position:relative;top:1px;left:2px;'/></a></span>"
                    + "<span class='tracking-ad' data-mod='popu_170'><a href='https://code.csdn.net/snippets/"
                    + snippet_id
                    + "/fork' target='_blank' title='派生到我的代码片' style='text-indent:0;'><img src='https://code.csdn.net/assets/ico_fork.svg' width=12 height=12 alt='派生到我的代码片' style='position:relative;top:2px;left:2px;'/></a></span>");
        }
        
        $("[code_snippet_id]").each(function () {
            __s_id = $(this).attr("code_snippet_id");
            if (__s_id != null && __s_id != "" && __s_id != 0 && parseInt(__s_id) > 70020) {
                __code_tool = __get_code_toolbar(__s_id);
                $(this).prev().find(".tools").append(__code_tool);
            }
        });


        $(".bar").show();
    });
</script>










    </div>
     




       <script type="text/javascript" src="http://static.blog.csdn.net/public/res/bower-libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>   
    
    <script src="http://static.blog.csdn.net/scripts/csdn_blog_detail.min.js?v2017.041" type="text/javascript"></script><link rel="stylesheet" type="text/css" href="//csdnimg.cn/pubfooter/css/pub_footer_2014.css"><div class="pub_fo"><div id="pub_footerall" class="pub_footer_new"><dl><dt></dt> <dd class="foot_sub_menu"><a href="http://www.csdn.net/company/about.html" target="_blank">公司简介</a><span>|</span><a href="http://www.csdn.net/company/recruit.html" target="_blank">招贤纳士</a><span>|</span><a href="http://www.csdn.net/company/marketing.html" target="_blank">广告服务</a><span>|</span><a href="http://www.csdn.net/company/contact.html" target="_blank">联系方式</a><span>|</span><a href="http://www.csdn.net/company/statement.html" target="_blank">版权声明</a><span>|</span><a href="http://www.csdn.net/company/layer.html" target="_blank">法律顾问</a><span>|</span><a href="mailto:webmaster@csdn.net">问题报告</a><span>|</span><a target="_blank" href="http://www.csdn.net/friendlink.html">合作伙伴</a><span>|</span><a href="http://bbs.csdn.net/forums/Service" target="_blank">论坛反馈</a></dd><dd class="foot_contact"><a href="javascript:void(0);" target="_blank" class="qq">网站客服</a><a href="http://wpa.qq.com/msgrd?v=3&amp;uin=2251809102&amp;site=qq&amp;menu=yes" target="_blank" class="qq">杂志客服</a><a href="http://e.weibo.com/csdnsupport/profile" target="_blank" class="weibo">微博客服</a><a href="mailto:webmaster@csdn.net" class="email" title="联系邮箱">webmaster@csdn.net</a><span class="phone" title="服务热线">400-660-0108</span><span class="interval">|</span><span>北京创新乐知信息技术有限公司 版权所有</span><span class="interval">|</span><span>江苏知之为计算机有限公司</span><span class="interval">|</span><span>江苏乐知网络技术有限公司</span></dd><dd class="foot_copyright"><span>京&nbsp;ICP&nbsp;证&nbsp;09002463&nbsp;号</span><span class="interval">|</span><span>Copyright © 1999-2017, CSDN.NET, All Rights Reserved&nbsp;</span><a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010" target="_blank"><img src="http://c.csdnimg.cn/pubfooter/images/gongshang_logos.gif" alt="GongshangLogo" title=""></a></dd></dl></div></div><div id="note1" class="csdn_note" style="display:none; position:absolute; z-index:9999; width:440px">  <span class="notice_top_arrow"><span class="inner"></span></span>  <div class="box"></div></div><div class="csdn_notice_tip" style="position: absolute; z-index: 9990; width: 170px; left: -72px; top: 18px; display: block;">  <iframe src="about:blank" frameborder="0" scrolling="no" style="z-index:-1;position:absolute;top:0;left:0;width:100%;height:100%;background:transparent"></iframe>  <div class="tip_text">您有<strong>274</strong>条新通知</div>  <a href="javascript:void 0" class="close2"></a></div><script id="noticeScript" type="text/javascript" btnid="header_notice_num" wrapid="note1" count="5" subcount="5" src="//csdnimg.cn/rabbit/notev2/js/notify.js?9d86d94"></script><input type="hidden" id="aa_g_data_ids">
        
    <script type="text/javascript" src="http://c.csdnimg.cn/blog/csdn_public_blog_detail.min.js?20170719001"></script>


    <script type="text/javascript" src="http://medal.blog.csdn.net/showblogmedal.ashx?blogid=647202"></script>




  <div id="a52b5334d" style="width: 1px; height: 1px; display: none;">
                    <script id="adJs52b5334" src="http://ads.csdn.net/js/opt/52b5334.js?t=0.1956578542003986"></script>
                    <script>document.getElementById("adJs52b5334").src = "http://ads.csdn.net/js/opt/52b5334.js?t=" + Math.random();</script>
   </div>
          
    <div class="pop_CA_cover" style="display:none"></div>
    <div class="pop pop_CA" style="display:none">
          <div class="CA_header">
            收藏助手
            <span class="cancel_icon" id="fapancle" onclick="$('.pop_CA').hide();$('.pop_CA_cover').hide();"></span>
          </div>
          <iframe src="" id="fa" frameborder="0" width="100%" height="360" scrolling="no"></iframe>
    </div>




        <script type="text/javascript">


            $(function () {
                var fromjs = $("#fromjs");
                if (fromjs.length > 0) {
                    $("#fromjs .markdown_views pre").addClass("prettyprint");
                    prettyPrint();


                    $('pre.prettyprint code').each(function () {
                        var lines = $(this).text().split('\n').length;
                        var $numbering = $('<ul/>').addClass('pre-numbering').hide();
                        $(this).addClass('has-numbering').parent().append($numbering);
                        for (i = 1; i <= lines; i++) {
                            $numbering.append($('<li/>').text(i));
                        };
                        $numbering.fadeIn(1700);
                    });


                    $('.pre-numbering li').css("color", "#999");
                }
            });


            $(".markdown_views a[target!='_blank']").attr("target", "_blank");


            //$(".toc a[target='_blank']").attr("target", "");


            setTimeout(function () {
                $(".toc a[target='_blank']").attr("target", "");
            }, 500);


        </script>




   
<link rel="stylesheet" type="text/css" media="screen" href="http://ask.csdn.net/assets/ask_float_fonts_css-6b30a53970eb5c3a2a045e3df585b475.css"><div data-mod="popu_64" class="csdn-tracking-statistics" chg-blk="0"><a id="com-quick-QRcode" class="QRcodebg1" title="扫描二维码" style="top:313px"><span class="closeQR"></span></a><a id="com-quick-reply" title="快速回复" style="top:447px"></a><a id="com-quick-collect" title="我要收藏" style="top:485px"></a><a id="com-d-top-a" style="top: 523px; display: none;" title="返回顶部" onclick=""></a></div><div class="pop_edit ask_second comm_ask_second"><h3>提问</h3><span class="ask_float_span">您的问题将会被发布在“<a class="ask_float_channel" href="//ask.csdn.net" target="_blank" style="cursor:pointer">技术问答</a>”频道</span><a href="#" nodetype="close" class="close">×</a><div class="context"><div class="err_div"><span class="err_ico"></span><span class="err_txt">该问题已存在,请勿重复提问</span></div><div class="input_div"><input id="askInputSecond" type="text" style="font-size:14px;" placeholder="问题标题"></div><div class="cm_box"><div class="cm_dialog"></div> <div class="pop_cm cm_add_link"><input type="text" placeholder="链接内容" id="af_cm_link_txt"><input type="text" placeholder="链接地址" id="af_cm_link_url"><input type="text" placeholder="链接提示" id="af_cm_link_tit"><div class="text-right"><span class="btn btn-default btn-sm" id="add_link_btn">插入链接</span> </div> </div><div class="pop_cm cm_add_img"><div class="nav-tabs"><a class="img_tab active" href="#tab_upload">本地上传</a><a class="img_tab" href="#tab_weburl">网络图片</a></div><div class="tab_panel active" id="tab_upload"><div class="set_img"></div></div><div class="tab_panel" id="tab_weburl"><input type="text" placeholder="图片地址" id="af_cm_img_url"><input type="text" placeholder="图片说明" id="af_cm_img_alt"><div class="text-right"><span class="btn btn-default btn-sm" id="add_img_btn">插入图片</span> </div></div> </div></div> <textarea id="editor_all" rows="8" style="display: none;"></textarea><div class="editor-toolbar"><i class="separator">|</i><a class="icon-headline" title="标题一(Ctrl+Alt+1)"></a><a class="icon-heading" title="标题二(Ctrl+Alt+2)"></a><a class="icon-bold" title="粗体(Ctrl+B)"></a><a class="icon-italic" title="斜体(Ctrl+I)"></a><i class="separator">|</i><a class="icon-quote-left" title="引用(Ctrl+’)"></a><a class="icon-code" title="插入代码片(Ctrl+,)"></a><a class="icon-list-ul" title="无序列表(Ctrl+L)"></a><a class="icon-list-ol" title="有序列表(Ctrl+Alt+L)"></a><i class="separator">|</i><a class="icon-link" title="添加链接(Ctrl+K)"></a><a class="icon-picture" title="添加图片(Ctrl+Alt+I)"></a><i class="separator">|</i><a class="icon-reply" title="撤退(Ctrl+Z)"></a><a class="icon-share-alt" title="前进(Ctrl+Shift+Z)"></a><i class="separator">|</i><a class="icon-info" href="http://ask.csdn.net/pages/markdown" target="_blank" title="markdown语法参考"></a><a class="icon-preview" title="预览"></a><i class="separator">|</i></div><div class="CodeMirror cm-s-paper CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 3px; height: 0px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" style="position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none; font-size: 4px;" tabindex="0"></textarea></div><div class="CodeMirror-hscrollbar"><div style="height: 1px;"></div></div><div class="CodeMirror-vscrollbar"><div style="width: 1px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-gutter-filler"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="min-width: 33px;"><div style="position: relative;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre>&nbsp;<span style="display: inline-block; width: 1px; margin-right: -1px;">&nbsp;</span></pre></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"></div><div class="CodeMirror-cursor" style="">&nbsp;</div><div class="CodeMirror-cursor CodeMirror-secondarycursor" style="">&nbsp;</div></div></div></div></div><div style="position: absolute; height: 30px; width: 1px;"></div><div class="CodeMirror-gutters" style="display: none;"></div></div></div><div class="editor-statusbar"><span class="lines">0</span><span class="words">0</span><span class="cursor">0:0</span></div><div class="div_tags clearfix"><div id="divSearchTags" class="tags_con"><input type="text"></div><input type="hidden" name="txtSearchTags"></div><div id="ask2_tagRecomm_div" class="drt_tagRecomm tracking-ad" data-mod="popu_73"><span class="drt_tit">推荐标签:</span></div></div><div class="success"><div class="left_area"><input id="chk_cb" type="checkbox"><span class="wyxs">我要悬赏</span><input id="cb_num" class="cb_num" readonly="true"><span class="phib_rii"><span> 币</span></span></div><a href="#" nodetype="cancel" class="cancel">取消</a><a href="#" nodetype="ok" class="ok">发布</a></div></div><div id="common_ask_div_sc" class="searchContainer"><div class="sTitle">可能存在类似的问题:</div><div class="sFooter"><a class="sFirstNewAsk">我想提一个新问题</a></div></div><div style="position:fixed; top:0; left:0; overflow:hidden;"><input style="position:absolute; left:-300px;" type="text" value="" id="focus_retriever" readonly="true"></div><iframe frameborder="0" id="bdSharePopup_1512724977506bg" class="bdshare_popup_bg" style="height: 326px; width: 118px; top: 23341.2px; left: 1420.5px; display: none;"></iframe><div class="bdshare_popup_box" id="bdSharePopup_1512724977506box" style="width: 116px; top: 23341.2px; left: 1420.5px; display: none;"><div class="bdshare_popup_top">分享到</div><ul class="bdshare_popup_list"><li><a href="#" onclick="return false;" class="popup_mshare" data-cmd="mshare">一键分享</a></li><li><a href="#" onclick="return false;" class="popup_qzone" data-cmd="qzone">QQ空间</a></li><li><a href="#" onclick="return false;" class="popup_tsina" data-cmd="tsina">新浪微博</a></li><li><a href="#" onclick="return false;" class="popup_bdysc" data-cmd="bdysc">百度云收藏</a></li><li><a href="#" onclick="return false;" class="popup_weixin" data-cmd="weixin">微信</a></li><li><a href="#" onclick="return false;" class="popup_renren" data-cmd="renren">人人网</a></li><li><a href="#" onclick="return false;" class="popup_tqq" data-cmd="tqq">腾讯微博</a></li><li><a href="#" onclick="return false;" class="popup_bdxc" data-cmd="bdxc">百度相册</a></li></ul><div class="bdshare_popup_bottom"><a href="#" onclick="return false;" class="popup_more" data-cmd="more" target="_blank;">更多...</a></div></div></body>
原创粉丝点击