一、概述
編寫目的
這個項目基本把電商的業務和平臺都完整的展示出來了,很多項目只是展示一個後臺管理,但是,那並不是完整的企業級項目,而這個lilishop卻是一個完整的項目,並且進行了開源代碼,在這裏要對其做出的貢獻表示感謝.
由於本系統的文檔不夠完善,缺少簡單的部署流程,使得很多新人,或沒有接觸這個系統的人,很難簡單快捷的實現,快速部署這個系統,同時,能夠快速搭建,學習起來的狀況,這也是目前國內開源的一大弊病,明明做的項目不差,但是由於文檔缺乏,配置繁瑣,導致很難快速上手,快速開發,快速學習,快速使用,所以,特此撰寫此文章,此文章爲原創設計,拒絕抄襲,如有轉載,請註明出處.
服務器部署
由於筆者是一個開發人員,所以部署主要以開發的部署到本地的情況爲主,文章這是範例,實際的問題,還需要自身學習百度功能,和自身對於一門技術的理解,希望大家努力學習,爭取自己領悟部署的方法,本文部署主要選取常用的windows系統作爲主要的部署環境,希望大家提高自身的部署能力.
二、基本構建
構建工具(參考文獻,其他版本安裝流程基本一樣)
三、Git 導入編譯器
四、模塊描述淺析
序號 |
模塊名稱 |
描述 |
1 |
admin |
監控模塊,用於監控整個系統的服務狀況 |
2 |
buyer-api |
買家接口模塊(就是你在商城想購物,你就是這個買家) |
3 |
common-api |
公共代碼模塊,list轉set什麼的一般放這裏,自己不要瞎寫方法,公共的都放這裏 |
4 |
config |
公共配置文檔的模塊.用於全局配置文件的修改,一般全局修改改這裏 |
5 |
consumer |
消費者模塊,消費服務,定時任務延時任務 |
6 |
DB |
數據腳本存放位置,本地部署前要跑一下數據庫的腳本 |
7 |
framework |
核心代碼(重點可以被學習的地方) |
8 |
lilishop-ui |
前段界面代碼模塊(三方的前臺代碼都在這裏) |
9 |
manager-api |
運營管理模塊,就是運營小姐姐給你處理訂單異常,售後,退款,這類問題的平臺 |
10 |
seller-api |
商家模塊(店鋪),你買的所有東西都是商家提供的,你看看淘寶每個商品點擊可以看到商鋪,這裏就是商鋪模塊,供應商提供貨源,平臺提供銷路 |
11 |
xxl-job |
定時任務管理模塊,跑一些定時或自動的業務 |
五、配置文檔
序號 |
名稱 |
位置 |
文件名稱 |
1 |
admin |
src/main/resources |
application.yml |
2 |
buyer-api |
src/main/resources |
application.yml |
3 |
common-api |
src/main/resources |
application.yml |
4 |
config |
src/main/resources |
application.yml |
5 |
consumer |
src/main/resources |
application.yml |
6 |
manager-api |
src/main/resources |
application.yml |
7 |
seller-api |
src/main/resources |
application.yml |
- 本文暫時以商城主頁的項目爲主教程,其他的模塊一樣,待自行舉一反三.
1.註釋配置文件
序號 |
名稱 |
位置 |
文件名稱 |
1 |
buyer-api |
src/main/resources |
application.yml |
2 |
common-api |
src/main/resources |
application.yml |
3 |
config |
src/main/resources |
application.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的配置,引入包位置
序號 |
名稱 |
位置 |
文件名稱 |
1 |
framework |
framework/ |
pom.yml |
序號 |
名稱 |
位置 |
文件名稱 |
1 |
lilishop |
lilishop/ |
pom.yml |
序號 |
名稱 |
位置 |
文件名稱 |
1 |
buyer-api |
src/main/resources |
application.yml |
2 |
common-api |
src/main/resources |
application.yml |
3 |
config |
src/main/resources |
application.yml |
spring:
mvc:
view:
prefix: /
suffix: .html
freemarker:
check-template-location: false
thymeleaf:
check-template-location: false
3.暫時關閉權限
- 由於除了忽略以外,本項目還開起了security的權限,如果不關閉這個權限,那麼還是無法訪問項目的swagger.
序號 |
名稱 |
位置 |
文件名稱 |
1 |
buyer-api |
src/main/java/security |
BuyerAuthenticationFilter 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.瀏覽器測試訪問
- 這裏有個神坑,本來界面部署好訪問應該是如下圖這樣,結果確實什麼都沒有(如上圖).
- 其實是因爲這個knife4j改版的時候,把docker的東西都結合在一起了,就是如下圖這樣,因爲只啓動了一個服務,所以,只能看到一個通用的接口文檔,它又排在最後,所以要使用下拉框.
- 下拉後,就找到通用,點擊通用,就會自動補全其下代碼,其他模塊也是這樣的.(knife4j的官方文檔真的很不友好,很多問題沒有答案,不夠普惠性,原來兩年前還是本博主寫的文檔解決了很多問題,請看參考,訪問量很高的,後期官方纔改進,現在依然不友好,就比如springboot和knife4j版本是怎麼對應的,官方文檔就沒有)
5.其他需要修改模塊
- 步驟與上述一樣,本博主相信你可以自行修改成功,加油,看好你!
序號 |
名稱 |
位置 |
文件名稱 |
1 |
admin |
src/main/resources |
application.yml |
2 |
consumer |
src/main/resources |
application.yml |
3 |
manager-api |
src/main/resources |
application.yml |
4 |
seller-api |
src/main/resources |
application.yml |
六、參考文獻
knife4j只用此插件的最簡潔開發方式
Knife4j添加lombok及註解初探
Knife4j 註解詳談
結語
嘔心瀝血,爆肝一個星期(需要寫配置環境的文檔,還要反覆測試,以便爲各位看官老爺提供最好的精品文章),希望點贊,收藏,評論,轉發,您的支持就是本博主前進的動力,後期將推出完整部署文檔,未完待續 .....