2022IDEA配置启动lilishop的swagger展示

博客 动态
0 197
优雅殿下
优雅殿下 2022-03-24 15:57:05
悬赏:0 积分 收藏

2022IDEA配置启动lilishop的swagger展示

目录
  • 一、概述
  • 二、基本构建
  • 三、Git 导入编译器
  • 四、模块描述浅析
  • 五、配置文档
    • 1.注释配置文件
    • 2.添加配置
    • 3.暂时关闭权限
    • 4.浏览器测试访问
    • 5.其他需要修改模块
  • 六、参考文献
  • 结语

一、概述

编写目的

这个项目基本把电商的业务和平台都完整的展示出来了,很多项目只是展示一个后台管理,但是,那并不是完整的企业级项目,而这个lilishop却是一个完整的项目,并且进行了开源代码,在这里要对其做出的贡献表示感谢.
由于本系统的文档不够完善,缺少简单的部署流程,使得很多新人,或没有接触这个系统的人,很难简单快捷的实现,快速部署这个系统,同时,能够快速搭建,学习起来的状况,这也是目前国内开源的一大弊病,明明做的项目不差,但是由于文档缺乏,配置繁琐,导致很难快速上手,快速开发,快速学习,快速使用,所以,特此撰写此文章,此文章为原创设计,拒绝抄袭,如有转载,请注明出处.

服务器部署

由于笔者是一个开发人员,所以部署主要以开发的部署到本地的情况为主,文章这是范例,实际的问题,还需要自身学习百度功能,和自身对于一门技术的理解,希望大家努力学习,争取自己领悟部署的方法,本文部署主要选取常用的windows系统作为主要的部署环境,希望大家提高自身的部署能力.

二、基本构建

构建工具(参考文献,其他版本安装流程基本一样)

软件名称版本描述
IntelliJ IDEA尽量使用比较新的版本https://www.jetbrains.com/idea/
JDK1.8https://www.cnblogs.com/liuyangfirst/p/14334385.html
Maven3.6.0https://www.cnblogs.com/liuyangfirst/p/15981202.html
MySQL官网使用5.7版本,本文采用最新的8.0版https://www.cnblogs.com/liuyangfirst/p/15997667.html
DBeaver7.3.0https://www.cnblogs.com/liuyangfirst/p/15997753.html
Redis5.0.10https://www.cnblogs.com/liuyangfirst/p/15998117.html
RedisDesktopManager0.9.3.817https://www.cnblogs.com/liuyangfirst/p/15998132.html
Mongodb4.2.5https://www.cnblogs.com/liuyangfirst/p/16011402.html
Robo3T1.4.2https://www.cnblogs.com/liuyangfirst/p/16014144.html
Elasticsearch7.6.2https://www.cnblogs.com/liuyangfirst/p/16004977.html
Kibana7.6.2https://www.cnblogs.com/liuyangfirst/p/16006164.html
Logstash7.6.2https://www.cnblogs.com/liuyangfirst/p/16008094.html
Git13.5.0https://www.cnblogs.com/liuyangfirst/p/15996063.html
NodeJS16.0.0https://www.cnblogs.com/liuyangfirst/p/15998172.html
RockeMQ16.0.0暂无

三、Git 导入编译器

  • git clone https://gitee.com/beijing_hongye_huicheng/docker.git

四、模块描述浅析

  • 文件路径: lilishop/pom.ml
序号模块名称描述
1admin监控模块,用于监控整个系统的服务状况
2buyer-api买家接口模块(就是你在商城想购物,你就是这个买家)
3common-api公共代码模块,list转set什么的一般放这里,自己不要瞎写方法,公共的都放这里
4config公共配置文档的模块.用于全局配置文件的修改,一般全局修改改这里
5consumer消费者模块,消费服务,定时任务延时任务
6DB数据脚本存放位置,本地部署前要跑一下数据库的脚本
7framework核心代码(重点可以被学习的地方)
8lilishop-ui前段界面代码模块(三方的前台代码都在这里)
9manager-api运营管理模块,就是运营小姐姐给你处理订单异常,售后,退款,这类问题的平台
10seller-api商家模块(店铺),你买的所有东西都是商家提供的,你看看淘宝每个商品点击可以看到商铺,这里就是商铺模块,供应商提供货源,平台提供销路
11xxl-job定时任务管理模块,跑一些定时或自动的业务

五、配置文档

序号名称位置文件名称
1adminsrc/main/resourcesapplication.yml
2buyer-apisrc/main/resourcesapplication.yml
3common-apisrc/main/resourcesapplication.yml
4configsrc/main/resourcesapplication.yml
5consumersrc/main/resourcesapplication.yml
6manager-apisrc/main/resourcesapplication.yml
7seller-apisrc/main/resourcesapplication.yml
  • 本文暂时以商城主页的项目为主教程,其他的模块一样,待自行举一反三.

1.注释配置文件

序号名称位置文件名称
1buyer-apisrc/main/resourcesapplication.yml
2common-apisrc/main/resourcesapplication.yml
3configsrc/main/resourcesapplication.yml
  • 注释以上三个模块的如下代码,这里的代码含义就是忽略这些接口的访问,不注释的话,以下接口无法访问.启动包含swagger的访问.
# 忽略鉴权url#ignored:#  urls:#    - /editor-app/**#    - /actuator**#    - /actuator/**#    - /MP_verify_qSyvBPhDsPdxvOhC.txt#    - /weixin/**#    - /source/**#    - /buyer/mini-program/**#    - /buyer/cashier/**#    - /buyer/pageData/**#    - /buyer/article/**#    - /buyer/goods/**#    - /buyer/category/**#    - /buyer/shop/**#    - /buyer/connect/**#    - /buyer/members/smsLogin#    - /buyer/members/refresh/*#    - /buyer/members/refresh**#    - /buyer/promotion/pintuan#    - /buyer/promotion/seckill#    - /buyer/memberEvaluation/**/goodsEvaluation#    - /buyer/memberEvaluation/**/evaluationNumber#    - /store/login/**#    - /manager/user/login#    - /manager/user/refresh/**#    - /druid/**#    - /swagger-ui.html#    - /doc.html#    - /swagger-resources/**#    - /swagger/**#    - /webjars/**#    - /v2/api-docs#    - /configuration/ui#    - /boot-admin#    - /**/*.js#    - /**/*.css#    - /**/*.png#    - /**/*.ico

2.添加配置

  • 由于本项目采用的是比较新的技术,叫做knife4j,所以配置要偏向于knife4j和swagger的配置,引入包位置
序号名称位置文件名称
1frameworkframework/pom.yml

  • 版本修改位置
序号名称位置文件名称
1lilishoplilishop/pom.yml

  • 在需要修改的模块,添加代码
序号名称位置文件名称
1buyer-apisrc/main/resourcesapplication.yml
2common-apisrc/main/resourcesapplication.yml
3configsrc/main/resourcesapplication.yml

spring:    mvc:      view:        prefix: /        suffix: .html      freemarker:        check-template-location: false      thymeleaf:        check-template-location: false

3.暂时关闭权限

  • 由于除了忽略以外,本项目还开起了security的权限,如果不关闭这个权限,那么还是无法访问项目的swagger.
序号名称位置文件名称
1buyer-apisrc/main/java/securityBuyerAuthenticationFilter
BuyerSecurityConfig
  • 由于项目比较复杂,为了达到简单高效的目的,第一步注释代码BuyerAuthenticationFilter,(不注释就算解开了权限,最后,还需要账户密码登陆,暂时没找到这个的登陆账号密码)

  • 修改代码BuyerSecurityConfig,使其跟common-api下的权限一致.

package cn.lili.security;import cn.lili.cache.Cache;import cn.lili.common.security.CustomAccessDeniedHandler;import cn.lili.common.utils.SpringContextUtil;import cn.lili.common.properties.IgnoredUrlsProperties;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Configuration;import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;import org.springframework.security.config.http.SessionCreationPolicy;import org.springframework.web.cors.CorsConfigurationSource;/** * spring Security 核心配置类 Buyer安全配置中心 * * @author Chopper * @version v4.0 * @since 2020/11/14 16:20 */@Slf4j@Configuration@EnableGlobalMethodSecurity(prePostEnabled = true)public class BuyerSecurityConfig extends WebSecurityConfigurerAdapter {    /**     * 忽略验权配置     */    @Autowired    private IgnoredUrlsProperties ignoredUrlsProperties;    /**     * spring security -》 权限不足处理     */    @Autowired    private CustomAccessDeniedHandler accessDeniedHandler;    @Autowired    private Cache<String> cache;    @Autowired    private CorsConfigurationSource corsConfigurationSource;    @Override    protected void configure(HttpSecurity http) throws Exception {  // 注释这里的过滤权限代码//        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http//                .authorizeRequests();//        //配置的url 不需要授权//        for (String url : ignoredUrlsProperties.getUrls()) {//            registry.antMatchers(url).permitAll();//        }//        registry//                .and()//                //禁止网页iframe//                .headers().frameOptions().disable()//                .and()//                .logout()//                .permitAll()//                .and()//                .authorizeRequests()//                //任何请求//                .anyRequest()//                //需要身份认证//                .authenticated()//                .and()//                //允许跨域//                .cors().configurationSource((CorsConfigurationSource) SpringContextUtil.getBean("corsConfigurationSource")).and()//                //关闭跨站请求防护//                .csrf().disable()//                //前后端分离采用JWT 不需要session//                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)//                .and()//                //自定义权限拒绝处理类//                .exceptionHandling().accessDeniedHandler(accessDeniedHandler)//                .and()//                //添加JWT认证过滤器//                .addFilter(new BuyerAuthenticationFilter(authenticationManager(), cache));        // 粘贴这里的不需要权限访问代码        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http                .authorizeRequests();        registry                .and()                //禁止网页iframe                .headers().frameOptions().disable()                .and()                .authorizeRequests()                //任何请求                .anyRequest()                //需要身份认证                .permitAll()                .and()                //允许跨域                .cors().configurationSource(corsConfigurationSource).and()                //关闭跨站请求防护                .csrf().disable();    }}

4.浏览器测试访问

  • http://localhost:8888/actuator

  • http://localhost:8888/actuator/beans

  • http://localhost:8888/doc.html,这是knife4j特有的访问方式,这里没有配置文档和接口文档,所以,你也无法用这个进行测试,需要进行测试就要自己添加注释,详细的knife4j问题请看相关推荐.

5.其他需要修改模块

  • 步骤与上述一样,本博主相信你可以自行修改成功,加油,看好你!
序号名称位置文件名称
1adminsrc/main/resourcesapplication.yml
2consumersrc/main/resourcesapplication.yml
3manager-apisrc/main/resourcesapplication.yml
4seller-apisrc/main/resourcesapplication.yml

六、参考文献

knife4j只用此插件的最简洁开发方式

Knife4j添加lombok及注解初探

Knife4j 注解详谈

结语

呕心沥血,爆肝一个星期(需要写配置环境的文档,还要反复测试,以便为各位看官老爷提供最好的精品文章),希望点赞,收藏,评论,转发,您的支持就是本博主前进的动力,后期将推出完整部署文档,未完待续 .....

posted @ 2022-03-24 15:44 北极的大企鹅 阅读(14) 评论(0) 编辑 收藏 举报
回帖
    优雅殿下

    优雅殿下 (王者 段位)

    2018 积分 (2)粉丝 (47)源码

    小小码农,大大世界

     

    温馨提示

    亦奇源码

    最新会员