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包就可以了


  • 相关阅读:
    Leetcode100.相同的树
    Leetcode53. 最大子序列和
    Leetcode35. 搜索插入位置
    Leetcode27.移除元素
    Leetcode 26. 删除排序数组中的重复项
    Leetcode. 1290 二进制链表转整数
    Leetcode.234 回文链表
    Leetcode206.反转链表
    课本 求素数
    循环法求素数 1306 循环求素数10.1.5.253 ====== 1313 筛选法求素数10.1.5.253
  • 原文地址:https://www.cnblogs.com/hbhb/p/14132539.html
Copyright © 2011-2022 走看看