<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Mall 電商實(shí)戰(zhàn)項(xiàng)目發(fā)布重大更新,全面支持SpringBoot 2.3.0 !

          共 7275字,需瀏覽 15分鐘

           ·

          2020-08-19 11:25

          之前寫了很多主流技術(shù)相關(guān)的文章,很多朋友反饋正是他們想學(xué)的技術(shù)!這些技術(shù)如果合適的話,我會(huì)把它們運(yùn)用到我的開源項(xiàng)目中去。最近mall項(xiàng)目升級(jí)改動(dòng)還是比較大的,所以寫了篇文章來(lái)介紹下更新的內(nèi)容,希望對(duì)大家有所幫助!

          更新內(nèi)容一覽

          • 升級(jí)至SpringBoot 2.3.0.RELEASE;
          • 支持Elasticsearch 7.6.2版本;
          • ELK日志收集功能完善,采用分場(chǎng)景收集日志的方案;
          • Swagger配置統(tǒng)一,簡(jiǎn)化配置;
          • Redis配置統(tǒng)一,簡(jiǎn)化配置;
          • Window和Linux部署文檔更新。

          更新內(nèi)容介紹

          升級(jí)SpringBoot 2.3.0

          之前一直使用的是SpringBoot 2.1.7版本,這個(gè)版本是2019年8月發(fā)布的,距離現(xiàn)在已經(jīng)一年多了,也到了更新版本的時(shí)候了。SpringBoot 2.3.0 是今年5月發(fā)布的,還是比較新的版本,想了解這個(gè)版本新特性的朋友可以看下《SpringBoot 2.3.0 新特性一覽,快來(lái)跟我實(shí)踐一波!》

          支持Elasticsearch 7.6.2

          由于SpringBoot版本的升級(jí),導(dǎo)致Elasticsearch被迫升級(jí),當(dāng)然Elasticsearch 7.x也是現(xiàn)在主流的版本。升級(jí)過(guò)程中踩了很多坑,具體可以看下《Elasticsearch 升級(jí) 7.x 版本后,我感覺掉坑里了!》

          ELK日志收集功能完善

          之前的日志收集功能一直都不是很完善,也沒有采用分場(chǎng)景收集日志的方法,這次終于完善了。日志收集系統(tǒng)搭建和分場(chǎng)景收集日志方案,可以參考《你居然還去服務(wù)器上撈日志,搭個(gè)日志收集系統(tǒng)難道不香么!》

          Swagger配置統(tǒng)一

          之前在各個(gè)模塊之中都有自己的Swagger配置,比如mall-adminmall-portalmall-search中都有自己的配置,現(xiàn)已進(jìn)行了統(tǒng)一。

          • 首先是在mall-common模塊中添加了Swagger的基礎(chǔ)配置BaseSwaggerConfig,在其他模塊中使用只需繼承該配置,并重寫swaggerProperties()這個(gè)抽象方法即可;
          /**
          ?*?Swagger基礎(chǔ)配置
          ?*?Created?by?macro?on?2020/7/16.
          ?*/

          public?abstract?class?BaseSwaggerConfig?{

          ????@Bean
          ????public?Docket?createRestApi()?{
          ????????SwaggerProperties?swaggerProperties?=?swaggerProperties();
          ????????Docket?docket?=?new?Docket(DocumentationType.SWAGGER_2)
          ????????????????.apiInfo(apiInfo(swaggerProperties))
          ????????????????.select()
          ????????????????.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
          ????????????????.paths(PathSelectors.any())
          ????????????????.build();
          ????????if?(swaggerProperties.isEnableSecurity())?{
          ????????????docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());
          ????????}
          ????????return?docket;
          ????}

          ????private?ApiInfo?apiInfo(SwaggerProperties?swaggerProperties)?{
          ????????return?new?ApiInfoBuilder()
          ????????????????.title(swaggerProperties.getTitle())
          ????????????????.description(swaggerProperties.getDescription())
          ????????????????.contact(new?Contact(swaggerProperties.getContactName(),?swaggerProperties.getContactUrl(),?swaggerProperties.getContactEmail()))
          ????????????????.version(swaggerProperties.getVersion())
          ????????????????.build();
          ????}

          ????private?List?securitySchemes()?{
          ????????//設(shè)置請(qǐng)求頭信息
          ????????List?result?=?new?ArrayList<>();
          ????????ApiKey?apiKey?=?new?ApiKey("Authorization",?"Authorization",?"header");
          ????????result.add(apiKey);
          ????????return?result;
          ????}

          ????private?List?securityContexts()?{
          ????????//設(shè)置需要登錄認(rèn)證的路徑
          ????????List?result?=?new?ArrayList<>();
          ????????result.add(getContextByPath("/*/.*"));
          ????????return?result;
          ????}

          ????private?SecurityContext?getContextByPath(String?pathRegex)?{
          ????????return?SecurityContext.builder()
          ????????????????.securityReferences(defaultAuth())
          ????????????????.forPaths(PathSelectors.regex(pathRegex))
          ????????????????.build();
          ????}

          ????private?List?defaultAuth()?{
          ????????List?result?=?new?ArrayList<>();
          ????????AuthorizationScope?authorizationScope?=?new?AuthorizationScope("global",?"accessEverything");
          ????????AuthorizationScope[]?authorizationScopes?=?new?AuthorizationScope[1];
          ????????authorizationScopes[0]?=?authorizationScope;
          ????????result.add(new?SecurityReference("Authorization",?authorizationScopes));
          ????????return?result;
          ????}

          ????/**
          ?????*?自定義Swagger配置
          ?????*/

          ????public?abstract?SwaggerProperties?swaggerProperties();
          }
          • 其中有個(gè)SwaggerProperties類是我們自定義的配置類,有哪些配置,看看注釋就清楚了;
          /**
          ?*?Swagger自定義配置
          ?*?Created?by?macro?on?2020/7/16.
          ?*/

          @Data
          @EqualsAndHashCode(callSuper?=?false)
          @Builder
          public?class?SwaggerProperties?{
          ????/**
          ?????*?API文檔生成基礎(chǔ)路徑
          ?????*/

          ????private?String?apiBasePackage;
          ????/**
          ?????*?是否要啟用登錄認(rèn)證
          ?????*/

          ????private?boolean?enableSecurity;
          ????/**
          ?????*?文檔標(biāo)題
          ?????*/

          ????private?String?title;
          ????/**
          ?????*?文檔描述
          ?????*/

          ????private?String?description;
          ????/**
          ?????*?文檔版本
          ?????*/

          ????private?String?version;
          ????/**
          ?????*?文檔聯(lián)系人姓名
          ?????*/

          ????private?String?contactName;
          ????/**
          ?????*?文檔聯(lián)系人網(wǎng)址
          ?????*/

          ????private?String?contactUrl;
          ????/**
          ?????*?文檔聯(lián)系人郵箱
          ?????*/

          ????private?String?contactEmail;
          }
          • mall-admin模塊中,只需繼承BaseSwaggerConfig,并配置好SwaggerProperties即可,是不是很方便!
          /**
          ?*?Swagger?API文檔相關(guān)配置
          ?*?Created?by?macro?on?2018/4/26.
          ?*/

          @Configuration
          @EnableSwagger2
          public?class?SwaggerConfig?extends?BaseSwaggerConfig?{

          ????@Override
          ????public?SwaggerProperties?swaggerProperties()?{
          ????????return?SwaggerProperties.builder()
          ????????????????.apiBasePackage("com.macro.mall.controller")
          ????????????????.title("mall后臺(tái)系統(tǒng)")
          ????????????????.description("mall后臺(tái)相關(guān)接口文檔")
          ????????????????.contactName("macro")
          ????????????????.version("1.0")
          ????????????????.enableSecurity(true)
          ????????????????.build();
          ????}
          }

          Redis配置統(tǒng)一

          在使用Redis時(shí),我們或多或少會(huì)自定義一些配置,該配置目前也統(tǒng)一了。

          • 首先是在mall-common模塊中添加了Redis的基礎(chǔ)配置BaseRedisConfig,在其他模塊中使用只需繼承該配置即可;
          /**
          ?*?Redis基礎(chǔ)配置
          ?*?Created?by?macro?on?2020/6/19.
          ?*/

          public?class?BaseRedisConfig?{

          ????@Bean
          ????public?RedisTemplate?redisTemplate(RedisConnectionFactory?redisConnectionFactory)?{
          ????????RedisSerializer?serializer?=?redisSerializer();
          ????????RedisTemplate?redisTemplate?=?new?RedisTemplate<>();
          ????????redisTemplate.setConnectionFactory(redisConnectionFactory);
          ????????redisTemplate.setKeySerializer(new?StringRedisSerializer());
          ????????redisTemplate.setValueSerializer(serializer);
          ????????redisTemplate.setHashKeySerializer(new?StringRedisSerializer());
          ????????redisTemplate.setHashValueSerializer(serializer);
          ????????redisTemplate.afterPropertiesSet();
          ????????return?redisTemplate;
          ????}

          ????@Bean
          ????public?RedisSerializer?redisSerializer()?{
          ????????//創(chuàng)建JSON序列化器
          ????????Jackson2JsonRedisSerializer?serializer?=?new?Jackson2JsonRedisSerializer<>(Object.class);
          ????????ObjectMapper?objectMapper?=?new?ObjectMapper();
          ????????objectMapper.setVisibility(PropertyAccessor.ALL,?JsonAutoDetect.Visibility.ANY);
          ????????//必須設(shè)置,否則無(wú)法將JSON轉(zhuǎn)化為對(duì)象,會(huì)轉(zhuǎn)化成Map類型
          ????????objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance,ObjectMapper.DefaultTyping.NON_FINAL);
          ????????serializer.setObjectMapper(objectMapper);
          ????????return?serializer;
          ????}

          ????@Bean
          ????public?RedisCacheManager?redisCacheManager(RedisConnectionFactory?redisConnectionFactory)?{
          ????????RedisCacheWriter?redisCacheWriter?=?RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
          ????????//設(shè)置Redis緩存有效期為1天
          ????????RedisCacheConfiguration?redisCacheConfiguration?=?RedisCacheConfiguration.defaultCacheConfig()
          ????????????????.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer())).entryTtl(Duration.ofDays(1));
          ????????return?new?RedisCacheManager(redisCacheWriter,?redisCacheConfiguration);
          ????}


          ????@Bean
          ????public?RedisService?redisService(){
          ????????return?new?RedisServiceImpl();
          ????}

          }
          • 比如我們?cè)?code style="font-size: 14px;overflow-wrap: break-word;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(239, 112, 96);">mall-security模塊中需要使用Redis,直接繼承該配置即可;
          /**
          ?*?Redis配置類
          ?*?Created?by?macro?on?2020/3/2.
          ?*/

          @EnableCaching
          @Configuration
          public?class?RedisConfig?extends?BaseRedisConfig?{

          }
          • 當(dāng)需要操作Redis時(shí),直接注入RedisService對(duì)象,然后使用它操作即可。
          /**
          ?*?UmsAdminCacheService實(shí)現(xiàn)類
          ?*?Created?by?macro?on?2020/3/13.
          ?*/

          @Service
          public?class?UmsAdminCacheServiceImpl?implements?UmsAdminCacheService?{
          ????@Autowired
          ????private?RedisService?redisService;
          }

          Window和Linux部署文檔更新

          由于部分組件的升級(jí),部署文檔也更新了,三種部署方式,總有一種適合你的!

          • mall在Windows環(huán)境下的部署:http://www.macrozheng.com/#/deploy/mall_deploy_windows
          • mall在Linux環(huán)境下的部署(基于Docker容器):http://www.macrozheng.com/#/deploy/mall_deploy_docker
          • mall在Linux環(huán)境下的部署(基于Docker Compose):http://www.macrozheng.com/#/deploy/mall_deploy_docker_compose

          項(xiàng)目地址

          如果覺得項(xiàng)目給力的話,請(qǐng)點(diǎn)個(gè)Star支持下吧!

          https://github.com/macrozheng/mall




          歡迎關(guān)注,點(diǎn)個(gè)在看





          瀏覽 54
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                    <th id="afajh"><progress id="afajh"></progress></th>
                    色婷婷网| 免费无遮挡 视频网乱码 | 日韩免费视频每日更新婷婷久久久 | 亚洲视频在线视频观看 | 国产精品久久久久久久免费大片 |