zoukankan      html  css  js  c++  java
  • springboot学习过程随记

    1.整合shiro+jwt(若忘记需结合测试代码springboot-mybatisplus-shiro-demo看)

    配置比较简单 定义一个类继承AuthorizingRealm 如下:

    (1)public class AccountRealm extends AuthorizingRealm
    重写里面的三个方法
    supports 令牌支持
    doGetAuthorizationInfo 权限获取

    doGetAuthenticationInfo身份验证(重点)
    其中protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
    入参token即jwttoken 就在这个类中定义token校验 失败抛异常


    (2)接着在@Configuration类定义@bean

    DefaultWebSecurityManager securityManager
    将AccountRealm传入配置(这部分代码是配置项)


    (3)最后开启shiro
    在需要开启shiro的方法中加上
    @RequiresAuthentication即开启



    2.开启跨域(cross方式)
    在视图解析器中重写addCorsMappings
    registry.addMapping("/**")
    .allowedOrigins("*")
    .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
    .allowCredentials(true)
    .maxAge(3600)
    .allowedHeaders("*");
    在需要跨域的方法中加上@CrossOrigin


    3.自定义启动类
    (1)新建一个模块 pom.xml只保留spring-boot-starter 其他的都删掉
    (2)主类加注解
    @Configuration
    @ConditionalOnWebApplication //注解意思是web项目时开启
    @EnableConfigurationProperties(HelloProperties.class)
      //HelloProperties.java中需有配置@ConfigurationProperties,这个注解让启动时HelloProperties注入 我自己理解类似于@component
    (3)接着在需启动的模块中加上启动的jar包就可以了


  • 相关阅读:
    html标签
    正则表达式判断号码靓号类型
    power函数:求底的n次幂
    php5.3的新特性
    xml方式操作txt文件
    什么是闭包?
    php设计模式单例模式
    面试总结
    统计ip代码
    XSL语言学习
  • 原文地址:https://www.cnblogs.com/hbhb/p/14132539.html
Copyright © 2011-2022 走看看