精华内容
下载资源
问答
  • 谷粒学院】阿里视频点播VOD功能笔记
    千次阅读
    2022-01-13 19:48:38

    1、准备工作

    首先配置文件中需要配置好阿里云相关id和密钥(和阿里云OSS配置一样)
    如果不知道id和密钥,就去阿里云官网进行服务开通申请就可以得到
    在这里插入图片描述

    2、代码详解

    配置类:用于读取配置文件中的id和密钥

    @Component
    public class ConstantVodUtil implements InitializingBean {
        @Value("${aliyun.vod.file.keyid}")
        private String keyId;
        @Value("${aliyun.vod.file.keysecret}")
        private String keySecret;
    
    
        public static String ACCESS_KEY_SECRET;
        public static String ACCESS_KEY_ID;
    
    
        @Override
        public void afterPropertiesSet() throws Exception {
            ACCESS_KEY_ID = keyId;
            ACCESS_KEY_SECRET = keySecret;
        }
    }
    

    Controller:

    @RestController
    @RequestMapping("/eduvod/video")
    public class VodController {
        @Autowired
        private VodService vodService;
    
        /**
         * 上传视频到阿里云
         */
        @PostMapping("/uplaodVideo")
        public R uplaodVideo(MultipartFile file) {
            //返回上传视频的id
            String videoId = vodService.uploadVideo(file);
            return R.ok().data("videoId", videoId);
        }
    }
    

    Service:

    @Service
    public class VodServiceImpl implements VodService {
        /**
         * 上传视频
         *
         * @param file
         * @return
         */
        @Override
        public String uploadVideo(MultipartFile file) {
            try {
                //上传文件的原始名称
                String fileName = file.getOriginalFilename();
                //上传后显示的名称,这里我想去掉后缀名,例如.mp4
                String title = fileName.substring(0, fileName.lastIndexOf("."));
                //文件输入流
                InputStream inputStream = file.getInputStream();
                UploadStreamRequest request = new UploadStreamRequest(ConstantVodUtil.ACCESS_KEY_ID,
                        ConstantVodUtil.ACCESS_KEY_SECRET, title, fileName, inputStream);
                UploadVideoImpl uploader = new UploadVideoImpl();
                UploadStreamResponse response = uploader.uploadStream(request);
                //获取到视频id(这个很重要,有了视频id从才可以获取播放地址和凭证)
                String videoId = response.getVideoId();
                return videoId;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
    }
    

    解释说明:为什么接口最终需要返回视频id?

    有了视频id,就可以通过官方SDK(就是api的意思)获取到视频的播放地址和凭证
    有了播放地址,就可以通过浏览器进行视频播放,那么凭证有什么用呢?
    项目中上传的视频一般需要通过模板转码进行加密,也就是说,不能直接通过网址进行播放
    也就是说,加密后的视频需要网址 + 凭证进行播放,否则无法播放视频 、

    3、测试结果

    通过swagger进行测试,可以上传成功,并且能拿到视频id:
    在这里插入图片描述
    阿里云媒资库中可有看到刚刚上传成功的视频,测试成功!
    在这里插入图片描述

    更多相关内容
  • 阿里java sdk源码 谷粒学院 谷粒学院项目致力于打造一个B2C模式的职业技能在线教育系统平台,采用现阶段流行技术来实现,采用前后端分离编写。 项目学习资源 项目文档 接口文档 谷粒学院后台接口: 谷粒学院后台UI:...
  • 基础篇\课件\谷粒商城-分布式基础-图.pdf 运维篇\课件\K8S部署&DevOps.pdf 高级篇\课件\01、Reactive&WebFlux.pdf 高级篇\课件\02、接口幂等性.pdf 高级篇\课件\03、本地事务&分布式事务.pdf 高级篇\课件\04、...
  • 谷粒商城全套资料.zip

    2021-02-20 11:09:44
    内含初级资料+高级资料和架构师资料等内容
  • 2020谷粒商城资料.rar

    2021-05-24 17:21:02
    2020谷粒商城资料全!
  • 谷粒商城是一个类似京东的自营商城平台,由业务集群系统+后台管理系统构成。 谷粒商城打通了分布式开发的全栈技能,包含前后分离全栈开发、Restful接口、数据校验、网关、注册发现、配置中心、熔断、限流、降级、 ...
  • 谷粒商城SQL语句文件

    2021-01-12 22:42:43
    谷粒商城分布式大型项目SQL语句文件,项目笔记专栏地址:https://blog.csdn.net/weixin_38297695/category_10730234.html
  • 谷粒在线教育》整合腾讯短信服务 注意事项:由于2021年阿里短信服务太严格了,小弟整了10次不行,所以换成腾讯刚好腾讯也有账号以前就一直用的腾讯 项目架构: 你也可以建一个spring Boot的单体微服务来做...
    注意事项:由于2021年阿里云短信服务太严格了,小弟整了10次不行,所以换成腾讯云刚好腾讯云也有账号以前就一直用的腾讯云

    项目架构:

    你也可以建一个spring Boot的单体微服务来做demo

    在这里插入图片描述

    第一步:进入腾讯云短信平台

    1.1、我感觉和阿里云没啥区别都一个吊样子

    在这里插入图片描述

    1.2、就和老师讲的阿里云一个样子,

    在这里插入图片描述

    1.3、进入腾讯云短信控制台

    在这里插入图片描述

    1.4、创建短信签名和短信模板

    在这里插入图片描述

    1.5、申请短信签名《小弟这里是有公众号的所以建议大家申请一下公众号》

    在这里插入图片描述

    1.6、嫌申请慢的话,直接找它客服,以前服务器和域名有问题的时候我都死里面投诉

    在这里插入图片描述

    在这里插入图片描述

    后续就不发了都是一些客套话

    1.7、申请短信模板,这是我的可以参考一下

    在这里插入图片描述

    在这里插入图片描述

    1.8、我感觉腾讯云的比阿里云的人工审核要快的多

    在这里插入图片描述

    在这里插入图片描述

    第二步:查看文档,引入依赖

    腾讯云SDK地址:https://cloud.tencent.com/document/sdk

    在这里插入图片描述

    <dependencies>
        <!--腾讯云sdk-->
        <dependency>
            <groupId>com.tencentcloudapi</groupId>
            <artifactId>tencentcloud-sdk-java</artifactId>
            <version>3.1.270</version>
        </dependency>
        <!--阿里巴巴json-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <!--redis-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>
    </dependencies>
    

    官网代码:

    import com.tencentcloudapi.common.Credential;
    import com.tencentcloudapi.common.exception.TencentCloudSDKException;
    
    //导入可选配置类
    import com.tencentcloudapi.common.profile.ClientProfile;
    import com.tencentcloudapi.common.profile.HttpProfile;
    
    // 导入对应SMS模块的client
    import com.tencentcloudapi.sms.v20210111.SmsClient;
    
    // 导入要请求接口对应的request response类
    import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
    import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
    
    /**
     * Tencent Cloud Sms Sendsms
     *
     */
    public class SendSms
    {
        public static void main(String[] args)
        {
            try {
                /* 必要步骤:
                 * 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。
                 * 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
                 * 你也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人,
                 * 以免泄露密钥对危及你的财产安全。
                 * CAM密匙查询: https://console.cloud.tencent.com/cam/capi*/
                Credential cred = new Credential("secretId", "secretKey");
    
                // 实例化一个http选项,可选,没有特殊需求可以跳过
                HttpProfile httpProfile = new HttpProfile();
                // 设置代理
                // httpProfile.setProxyHost("真实代理ip");
                // httpProfile.setProxyPort(真实代理端口);
                /* SDK默认使用POST方法。
                 * 如果你一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */
                httpProfile.setReqMethod("POST");
                /* SDK有默认的超时时间,非必要请不要进行调整
                 * 如有需要请在代码中查阅以获取最新的默认值 */
                httpProfile.setConnTimeout(60);
                /* SDK会自动指定域名。通常是不需要特地指定域名的,但是如果你访问的是金融区的服务
                 * 则必须手动指定域名,例如sms的上海金融区域名: sms.ap-shanghai-fsi.tencentcloudapi.com */
                httpProfile.setEndpoint("sms.tencentcloudapi.com");
    
                /* 非必要步骤:
                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
                ClientProfile clientProfile = new ClientProfile();
                /* SDK默认用TC3-HMAC-SHA256进行签名
                 * 非必要请不要修改这个字段 */
                clientProfile.setSignMethod("HmacSHA256");
                clientProfile.setHttpProfile(httpProfile);
                /* 实例化要请求产品(以sms为例)的client对象
                 * 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,或者引用预设的常量 */
                SmsClient client = new SmsClient(cred, "ap-guangzhou",clientProfile);
                /* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
                 * 你可以直接查询SDK源码确定接口有哪些属性可以设置
                 * 属性可能是基本类型,也可能引用了另一个数据结构
                 * 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */
                SendSmsRequest req = new SendSmsRequest();
    
                /* 填充请求参数,这里request对象的成员变量即对应接口的入参
                 * 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义
                 * 基本类型的设置:
                 * 帮助链接:
                 * 短信控制台: https://console.cloud.tencent.com/smsv2
                 * sms helper: https://cloud.tencent.com/document/product/382/3773 */
    
                /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
                String sdkAppId = "1400009099";
                req.setSmsSdkAppId(sdkAppId);
    
                /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,签名信息可登录 [短信控制台] 查看 */
                String signName = "签名内容";
                req.setSignName(signName);
    
                /* 国际/港澳台短信 SenderId: 国内短信填空,默认未开通,如需开通请联系 [sms helper] */
                String senderid = "";
                req.setSenderId(senderid);
    
                /* 用户的 session 内容: 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
                String sessionContext = "xxx";
                req.setSessionContext(sessionContext);
    
                /* 短信号码扩展号: 默认未开通,如需开通请联系 [sms helper] */
                String extendCode = "";
                req.setExtendCode(extendCode);
    
                /* 模板 ID: 必须填写已审核通过的模板 ID。模板ID可登录 [短信控制台] 查看 */
                String templateId = "400000";
                req.setTemplateId(templateId);
    
                /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
                 * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */
                String[] phoneNumberSet = {"+8621212313123", "+8612345678902", "+8612345678903"};
                req.setPhoneNumberSet(phoneNumberSet);
    
                /* 模板参数: 若无模板参数,则设置为空 */
                String[] templateParamSet = {"5678"};
                req.setTemplateParamSet(templateParamSet);
    
                /* 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的
                 * 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应 */
                SendSmsResponse res = client.SendSms(req);
    
                // 输出json格式的字符串回包
                System.out.println(SendSmsResponse.toJsonString(res));
    
                // 也可以取出单个值,你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
                System.out.println(res.getRequestId());
    
            } catch (TencentCloudSDKException e) {
                e.printStackTrace();
            }
        }
    }
    

    第三步:编写代码

    application.yaml
    server:
      port: 8005
    spring:
      application:
        name: guli-service-msm
      profiles:
        active: dev
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/guli-education?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: 130428
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
      redis:
        host: 192.168.47.128
        port: 6379
        database: 0
        timeout: 180000
        lettuce:
          pool:
            max-active: 20
            max-wait: 1
            max-idle: 5
            min-idle: 0
    #整合腾讯云短信
    tengxun:
      msm:
        sdk:
          SecretId:  #填写你的腾讯云密钥
          SecretKey: #填写你的腾讯云密钥
    mybatis-plus:
      #  configuration:
      #    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
      mapper-locations: classpath:/mapper/*.xml
      type-aliases-package: com.education.entit
    
    查看你自己腾讯云密钥网址:https://console.cloud.tencent.com/cam/capi 短信验证一下就能知道你的SecretKey

    MsmPropertiesUtils.Java

    package com.education.utils;
    
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Component;
    
    //封装方式和阿里云的oss,vod一样
    @Component
    public class MsmPropertiesUtils implements InitializingBean {
    
        @Value("${tengxun.msm.sdk.SecretId}")
        private String secretId;
    
        @Value("${tengxun.msm.sdk.SecretKey}")
        private String secretKey;
    
    
        public static String SECRET_ID;
        public static String SECRET_KEY;
    
        @Override
    
        public void afterPropertiesSet() throws Exception {
            SECRET_ID = secretId;
            SECRET_KEY = secretKey;
    
        }
    }
    
    
    RandomUtils.Java
    package com.education.utils;
    
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Random;
    
    /**
     * 获取随机验证码工具类
     */
    public class RandomUtils {
    
        private static final Random random = new Random();
    
        private static final DecimalFormat fourdf = new DecimalFormat("0000");
    
        private static final DecimalFormat sixdf = new DecimalFormat("000000");
    
        public static String getFourBitRandom() {
            return fourdf.format(random.nextInt(10000));
        }
    
        public static String getSixBitRandom() {
            return sixdf.format(random.nextInt(1000000));
        }
    
        /**
         * 给定数组,抽取n个数据
         *
         * @param list
         * @param n
         * @return
         */
        public static ArrayList<?> getRandom(List<?> list, int n) {
    
            Random random = new Random();
    
            HashMap<Object, Object> hashMap = new HashMap<Object, Object>();
    
            // 生成随机数字并存入HashMap
            for (int i = 0; i < list.size(); i++) {
    
                int number = random.nextInt(100) + 1;
    
                hashMap.put(number, i);
            }
    
            // 从HashMap导入数组
            Object[] robjs = hashMap.values().toArray();
    
            ArrayList<Object> r = new ArrayList<Object>();
    
            // 遍历数组并打印数据
            for (int i = 0; i < n; i++) {
                r.add(list.get((int) robjs[i]));
                System.out.print(list.get((int) robjs[i]) + "\t");
            }
            System.out.print("\n");
            return r;
        }
    }
    
    MsmService.Java
    package com.education.service;
    
    public interface MsmService {
        boolean send(String code, String phone);
    }
    
    
    MsmServiceImpl.Java
    package com.education.service.Impl;
    
    import com.education.service.MsmService;
    import com.education.utils.MsmPropertiesUtils;
    import com.tencentcloudapi.common.Credential;
    import com.tencentcloudapi.common.profile.ClientProfile;
    import com.tencentcloudapi.common.profile.HttpProfile;
    import com.tencentcloudapi.sms.v20210111.SmsClient;
    import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
    import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
    import org.springframework.stereotype.Service;
    
    @Service
    public class MsmServiceImpl implements MsmService {
    
    
        @Override
        public boolean send(String code, String phone) {
            try {
                String secretId = MsmPropertiesUtils.SECRET_ID;
                String secretKey = MsmPropertiesUtils.SECRET_KEY;
                //创建实例化认证对象
                Credential credential = new Credential(secretId, secretKey);
                //创建http选项
                HttpProfile httpProfile = new HttpProfile();
                //设置endPoint
                httpProfile.setEndpoint("sms.tencentcloudapi.com");
                //创建客户端配置对象
                ClientProfile clientProfile = new ClientProfile();
                clientProfile.setHttpProfile(httpProfile);
                //这里的region参数一定要写,我看见帖子上好多人不写,官网也说不写就是默认参数
                SmsClient client = new SmsClient(credential, "ap-beijing", clientProfile);
                SendSmsRequest request = new SendSmsRequest();
                //创建手机号数组
                String[] phone1 = {"+86" + phone};
                //创建验证码数组
                String[] templateParamsSet1 = {code};
                request.setPhoneNumberSet(phone1);
                request.setTemplateParamSet(templateParamsSet1);
                //短信签名
                request.setSignName("你的短信签名模板名称");
                //短信SdkId
                request.setSmsSdkAppId("1400605809");
                request.setTemplateId("1224748");
                SendSmsResponse sendSmsResponse = client.SendSms(request);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
    }
    
    
    关于这里我想说一下,不填写region参数的报的错误

    在这里插入图片描述

    [TencentCloudSDKException]code: MissingParameter message:The request is missing a required parameter `Region`. requestId:6dcd5dd8-4329-4520-b279-ff8bba68ed82
    
    点开查看支持的地域列表,并不是默认就行了,好像用版本低的没事儿

    在这里插入图片描述

    第四步:测试发送短信接口

    在这里插入图片描述

    第五步:发送验证码

    在这里插入图片描述

    第六步:查看redis

    在这里插入图片描述

    第七步:手机上接受验证码

    在这里插入图片描述

    展开全文
  • 阿里视频点播服务与谷粒学院整合视频点播技术 一.应用场景 音视频网站:无论是初创视频服务企业,还是已拥有海量视频资源,可定制化的点播服务帮助客户快速搭建拥有极致观看体验、安全可靠的视频点播应用。 短...

    阿里云视频点播服务与谷粒学院整合视频点播技术

    一.应用场景

    • 音视频网站:无论是初创视频服务企业,还是已拥有海量视频资源,可定制化的点播服务帮助客户快速搭建拥有极致观看体验、安全可靠的视频点播应用。
    • 短视频:集音视频拍摄、特效编辑、本地转码、高速上传、自动化云端转码、媒体资源管理、分发加速、播放于一体的完整短视频解决方案。目前已帮助1000+APP快速实现手机短视频功能。
    • 直播转点播:将直播流同步录制为点播视频,用于回看。并支持媒资管理、媒体处理(转码及内容审核/智能首图等AI处理)、内容制作(云剪辑)、CDN分发加速等一系列操作。
    • 在线教育:为在线教育客户提供简单易用、安全可靠的视频点播服务。可通过控制台/API等多种方式上传教学视频,强大的转码能力保证视频可以快速发布,覆盖全网的加速节点保证学生观看的流畅度。防盗链、视频加密等版权保护方案保护教学内容不被窃取。
    • 视频生产制作:提供在线可视化剪辑平台及丰富的OpenAPI,帮助客户高效处理、制作视频内容。除基础的剪切拼接、混音、遮标、特效、合成等一系列功能外,依托云剪辑及点播一体化服务还可
    • 实现标准化、智能化剪辑生产,大大降低视频制作的槛,缩短制作时间,提升内容生产效率。
    • 内容审核:应用于短视频平台、传媒行业审核等场景,帮助客户从从语音、文字、视觉等多维度精准识别视频、封面、标题或评论的违禁内容进行AI智能审核与人工审核。

    二.功能介绍

    在这里插入图片描述

    三.视频点播的整体流程

    在这里插入图片描述

    四.使用实例

    4.1根据视频地址进行播放(未加密的视频)

    直接根据视频的地址进行视频的播放

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css" />
         <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js"></script>
        <!-- <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css" />
        <script charset="utf-8" type="text/javascript"
            src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"></script> -->
    </head>
    
    <body>
        <body><div class="prism-player" id="J_prismPlayer"></div> <script>
            var player = new Aliplayer({
            id: 'J_prismPlayer',
            width: '50%',
            autoplay: false,
            cover: 'https://sunset-education.oss-cn-beijing.aliyuncs.com/2021/07/22/07da8844645c4485a8fe7d18a23353c003.jpg',
            //播放配置
            source : 'https://outin-d7002059ed2311eb821700163e1c955c.oss-cn-shanghai.aliyuncs.com/sv/352c58b0-17b05d4fe47/352c58b0-17b05d4fe47.mp4?Expires=1628246744&OSSAccessKeyId=LTAIVVfYx6D0HeL2&Signature=VXcZEUAdJjAC7TY%2Fgy8yJGZGqjE%3D',
             },function(player){
            console.log('播放器创建好了。')
             });
            </script>
            </body>
    
    </body>
    
    </html>
    

    4.2根据视频的播放凭证进行播放

    步骤:

    1. 根据阿里云上传的视频id获取视频的播放凭证
    2. 根据播放凭证获取视频的播放信息

    注意:那一大段很长的就是视频的凭证,现在是直接给,后期整合后则是根据视频的id进行获取

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css" />
         <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js"></script>
    </head>
    
    <body>
        <body><div class="prism-player" id="J_prismPlayer"></div> <script>
            var player = new Aliplayer({
            id: 'J_prismPlayer',
            width: '50%',
            autoplay: false,
            cover: 'https://sunset-education.oss-cn-beijing.aliyuncs.com/2021/07/22/07da8844645c4485a8fe7d18a23353c003.jpg',
            encryptType:'1',//如果播放加密视频,则需设置encryptType=1,非加密视频无需设置此项
            vid : '5adbc05402e048aab30121542f617476',
            playauth : 'eyJTZWN1cml0eVRva2VuIjoiQ0FJU2h3TjFxNkZ0NUIyeWZTaklyNVdOT2VpTnVJZHM3YmVjZTAzcGwzVUVPL2hVaUtmU2h6ejJJSHBOZTNocUIrMGZzUGt3bEdsVTZmZ2Nsck1xRWNVYUhSYWFQWll0czhRTHJsNzZKcExGc3QySjZyOEpqc1VCeGQxODAxbXBzdlhKYXNEVkVmbDJFNVhFTWlJUi8wMGU2TC8rY2lyWXBUWEhWYlNDbFo5Z2FQa09Rd0M4ZGtBb0xkeEtKd3hrMnQxNFVtWFdPYVNDUHdMU2htUEJMVXhtdldnR2wyUnp1NHV5M3ZPZDVoZlpwMXI4eE80YXhlTDBQb1AyVjgxbExacGxlc3FwM0k0U2M3YmFnaFpVNGdscjhxbHg3c3BCNVN5Vmt0eVdHVWhKL3phTElvaXQ3TnBqZmlCMGVvUUFQb3BGcC9YNmp2QWF3UExVbTliWXhncGhCOFIrWGo3RFpZYXV4N0d6ZW9XVE84MCthS3p3TmxuVXo5bUxMZU9WaVE0L1ptOEJQdzQ0RUxoSWFGMElVRTF4Rm11Q2QvWDRvQXlhTzF2NkdwTG9pdjltamNCSHFIeno1c2VQS2xTMVJMR1U3RDBWSUpkVWJUbHpiVWRKakRhL0wvWllMbE1jS2c4NFdlaVBNYXgzYlFGRHI1M3ZzVGJiWHpaYjBtcHR1UG56ZHhBS0RqK2FxMUdVR29BQmZyZmpTSmU3RnNBdkJQbWhjaHY0TFBBdEM0c1RwTkw2RE0zaUtKRkZOMGdFek5xOTFLZWhsTWJQaUZ6UWE0RDNkK2YyT2pWWjVVTWk1SklEckN4cEh1OFh3M3BzVXdndzExQ0x0cW9iTG5FMWdyMHFyVzRjUjdLWTA2WWhnaEpKb0RtdEZ5QTEycVA0Y2VQa3BHMzhKelBEb3Y1SksxdXFVMW9ZQW9EREpHcz0iLCJBdXRoSW5mbyI6IntcIkNJXCI6XCJZZmVqUS8wWmZyeERRTlkvNUw5MDcxSjlZam1pcEVnS1dlTzZmRE1raCtZcHlUR1hmQWUzSXFNRDZ0blZ3T2Q3XCIsXCJDYWxsZXJcIjpcIk1FbFhNcU16RmhNQ2JrR2orNWNwV3lBVU4xbndkaTg4Z1Fub09VU09CUE09XCIsXCJFeHBpcmVUaW1lXCI6XCIyMDIxLTA4LTAxVDA4OjEyOjAyWlwiLFwiTWVkaWFJZFwiOlwiNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzZcIixcIlNpZ25hdHVyZVwiOlwiQThtUDNKUUVIa1FEcWJZYzdoZytlUDJESjUwPVwifSIsIlZpZGVvTWV0YSI6eyJTdGF0dXMiOiJOb3JtYWwiLCJWaWRlb0lkIjoiNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzYiLCJUaXRsZSI6InZpZGVvLm1wNCIsIkNvdmVyVVJMIjoiaHR0cDovL291dGluLWQ3MDAyMDU5ZWQyMzExZWI4MjE3MDAxNjNlMWM5NTVjLm9zcy1jbi1zaGFuZ2hhaS5hbGl5dW5jcy5jb20vNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzYvc25hcHNob3RzL2Q1ZjM1YzU1ZWE1YzQyODViODc4YTI3YmZjZDIwNTQ3LTAwMDAxLmpwZz9FeHBpcmVzPTE2Mjc4MDkwMjImT1NTQWNjZXNzS2V5SWQ9TFRBSVZWZll4NkQwSGVMMiZTaWduYXR1cmU9MkVVQnY4dXElMkZDaFlJdFVrWmlWdXNSOTg5OHMlM0QiLCJEdXJhdGlvbiI6MTIuNTE1fSwiQWNjZXNzS2V5SWQiOiJTVFMuTlY4clI5VVhNWnV3eWtYc3VRN3d4Z2J5ZSIsIkFjY2Vzc0tleVNlY3JldCI6IkVUVW94Tm44RHdicnZSd1hnd21meE1zTkZVVWRIMzVjaTFwdlVoUmVYclJGIiwiUmVnaW9uIjoiY24tc2hhbmdoYWkiLCJDdXN0b21lcklkIjoxMjI3MDI2ODU1NTg0NzUzfQ==',
             },function(player){
            console.log('播放器创建好了。')
             });
            </script>
            </body>
    
    </body>
    
    </html>
    

    五.谷粒学院整合阿里云视频点播服务

    1. 创建一个新的模块在这里插入图片描述

    2. 导入相关依赖

    <dependencies>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-vod</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-vod</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-sdk-vod-upload</artifactId>
        </dependency>
    
        </dependencies>
    
    1. 将阿里云的keyid等配置好
    2. 创建一个工具类,用来创建DefaultAcsClient对象
    package com.sunset.vod.utils;
    
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.profile.DefaultProfile;
    
    /**
     * 初始化操作,创建DefaultAcsClient对象
     */
    public class InitObject {
        public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
            String regionId = "cn-shanghai";  // 点播服务接入区域
            DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
            DefaultAcsClient client = new DefaultAcsClient(profile);
            return client;
        }
    }
    
    
    1. 根据视频id获取视频凭证,并传递给前端使用

      //    根据视频id获取视频播放凭证
          @GetMapping("/getPlayAuth/{id}")
          public Result getPlayAuth(@PathVariable String id){
              try {
      //            创建初始化对象
                  DefaultAcsClient defaultAcsClient = InitObject.initVodClient(ConstantVodUtils.ACCESS_KEY_ID, ConstantVodUtils.ACCESS_KEY_SECRET);
                  //            创建获取视频凭证的request和response对象
                  GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
      //            设置视频id值
                  request.setVideoId(id);
      //            调用初始化对象的方法
                  GetVideoPlayAuthResponse response = defaultAcsClient.getAcsResponse(request);
      //            获取凭证
                  String playAuth = response.getPlayAuth();
                  System.out.println("==========="+playAuth);
                  return Result.ok().data("playAuth",playAuth);
              }catch (Exception e){
                  throw  new SunsetException(20001,"播放视频失败");
              }
          }
      
    2. 前端定义接口,并进行调用

    import request from '@/utils/request'
    
    export default{
        // 根据视频id获取视频播放凭证
        getPlayAuth(id){
            return request({
                url:'/eduvod/video/getPlayAuth/'+id,
                method:'get'
            })
        }
    }
    
    <template>
      <div>
     <!-- 阿里云视频播放器样式 -->
          <!-- <link rel="stylesheet"
           href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css"
           /> -->
           <!-- 阿里云视频播放器脚本 -->
         <!-- <script 
          charset="utf-8" 
          type="text/javascript" 
          src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js">
         </script> -->
       
        <link
          rel="stylesheet"
          href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css"
        />
        
        <script
          charset="utf-8"
          type="text/javascript"
          src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"
        />
    
        <!-- 定义播放器dom -->
        <div id="J_prismPlayer" class="prism-player" />
      </div>
    </template>
    
    <script>
    import vodApi from '@/api/vod'
    export default {
        layout: 'video',//应用video布局
        data(){
          return{
            // playAuth:'',
            // vid:''
          }
        },
        asyncData({ params, error }) {
          return vodApi.getPlayAuth(params.vid).then(response=>{
             return {
                    vid:params.vid,
                    playAuth:response.data.data.playAuth
                }
          })
               
        },
        mounted(){//页面渲染之后执行这个方法,因为前面是异步请求视频的播放凭证,所以使用created的话,可能获取不到数据
            new Aliplayer({
                id: 'J_prismPlayer',
                vid: this.vid, // 视频id
                playauth: this.playAuth, // 播放凭证
                // source : 'https://outin-d7002059ed2311eb821700163e1c955c.oss-cn-shanghai.aliyuncs.com/sv/352c58b0-17b05d4fe47/352c58b0-17b05d4fe47.mp4?Expires=1628246744&OSSAccessKeyId=LTAIVVfYx6D0HeL2&Signature=VXcZEUAdJjAC7TY%2Fgy8yJGZGqjE%3D',
                encryptType: '1', // 如果播放加密视频,则需设置encryptType=1,非加密视频无需设置此项
                width: '100%',
                height: '500px',
                cover: 'http://guli.shop/photo/banner/1525939573202.jpg', // 封面
                qualitySort: 'asc', // 清晰度排序
                mediaType: 'video', // 返回音频还是视频
                autoplay: false, // 自动播放
                isLive: false, // 直播
                rePlay: false, // 循环播放
                preload: true,
                controlBarVisibility: 'hover', // 控制条的显示方式:鼠标悬停
                useH5Prism: true, // 播放器类型:html5
                }, function(player) {
                console.log('播放器创建成功')
                })
        },
        methods:{
          init(){
             vodApi.getPlayAuth(this.vid).then(response=>{
            this.playAuth = response.data.data.playAuth
            // console.log(this.vid)
            // console.log(this.playAuth)
          })
          },
        }
    
    };
    </script>
    
    <style>
    </style>
    
    1. 测试

    在这里插入图片描述
    成功!!!

    展开全文
  • 完整的springboot谷粒商城文档,该项目对于学习非常有帮助,涵盖了分布式、dubbo、zookeeper、消息队列以及各种分布式大型项目所用到的技术。每个步骤都写的非常详细,在这个压缩包中带有bean实体类代码以及html界面...
  • 谷粒学院-阿里短信服务

    千次阅读 2022-03-27 15:17:01
    } } 阿里短信服务 个人用户用不了哇,算啦 阿里登录 - 欢迎登录阿里,安全稳定的云计算服务平台 编写发送短信接口 可以参考阿里官方文档 短信发送API(SendSms)---Java - 短信服务 - 阿里 在service_...

    新建短信微服务

    1、在service模块下创建子模块service_msm

    2、创建controller和service代码

    3、配置application.properties

    # 服务端口
    server.port=8005
    # 服务名
    spring.application.name=service-msm
    
    # mysql数据库连接
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8
    spring.datasource.username=root
    spring.datasource.password=123456
    
    spring.redis.host=127.0.0.1
    spring.redis.port=6379
    spring.redis.database= 0
    spring.redis.timeout=1800000
    
    spring.redis.lettuce.pool.max-active=20
    spring.redis.lettuce.pool.max-wait=-1
    #最大阻塞等待时间(负数表示没限制)
    spring.redis.lettuce.pool.max-idle=5
    spring.redis.lettuce.pool.min-idle=0
    #最小空闲
    
    #返回json的全局时间格式
    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    spring.jackson.time-zone=GMT+8
    
    #mybatis日志
    mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
    

    4、创建启动类

    package com.nanjing.msmservice;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    import org.springframework.context.annotation.ComponentScan;
    
    /**
     * @author yimo
     * @version 1.0
     * @date 2022/3/27 17:23
     */
    @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    @ComponentScan(basePackages = {"com.nanjing"})
    public class MsmApplication {
        public static void main(String[] args) {
            SpringApplication.run(MsmApplication.class,args);
        }
    }
    

    阿里云短信服务

     

     

    个人用户用不了哇,算啦

     阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台


    编写发送短信接口

    可以参考阿里云官方文档

    短信发送API(SendSms)---Java - 短信服务 - 阿里云 

    在service_msm的pom中引入依赖

    <dependencies>
       <dependency>
           <groupId>com.alibaba</groupId>
           <artifactId>fastjson</artifactId>
       </dependency>
       <dependency>
           <groupId>com.aliyun</groupId>
           <artifactId>aliyun-java-sdk-core</artifactId>
       </dependency>
    </dependencies>
    

    随机数工具类

    package com.nanjing.msmservice.utils;
    
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Random;
    
    /**
     * @author yimo
     * @version 1.0
     * @date 2022/3/27 18:36
     */
    public class RandomUtil {
    
        private static final Random random = new Random();
    
        private static final DecimalFormat fourdf = new DecimalFormat("0000");
    
        private static final DecimalFormat sixdf = new DecimalFormat("000000");
    
        public static String getFourBitRandom() {
            return fourdf.format(random.nextInt(10000));
        }
    
        public static String getSixBitRandom() {
            return sixdf.format(random.nextInt(1000000));
        }
    
        /**
         * 给定数组,抽取n个数据
         * @param list
         * @param n
         * @return
         */
        public static ArrayList getRandom(List list, int n) {
    
            Random random = new Random();
    
            HashMap<Object, Object> hashMap = new HashMap<Object, Object>();
    
            // 生成随机数字并存入HashMap
            for (int i = 0; i < list.size(); i++) {
    
                int number = random.nextInt(100) + 1;
    
                hashMap.put(number, i);
            }
    
            // 从HashMap导入数组
            Object[] robjs = hashMap.values().toArray();
    
            ArrayList r = new ArrayList();
    
            // 遍历数组并打印数据
            for (int i = 0; i < n; i++) {
                r.add(list.get((int) robjs[i]));
                System.out.print(list.get((int) robjs[i]) + "\t");
            }
            System.out.print("\n");
            return r;
        }
    
    }
    

    controller和service代码

    重点:

    package com.nanjing.msmservice.controller;
    
    import com.nanjing.commonutils.R;
    import com.nanjing.msmservice.service.MsmService;
    import com.nanjing.msmservice.utils.RandomUtil;
    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.redis.core.RedisTemplate;
    import org.springframework.web.bind.annotation.*;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.concurrent.TimeUnit;
    
    /**
     * @author yimo
     * @version 1.0
     * @date 2022/3/27 17:24
     */
    @Api(description = "短信服务")
    @RestController
    @RequestMapping("/edumsm/msm")
    @CrossOrigin
    public class MsmController {
    
        @Autowired
        private MsmService msmService;
    
        @Autowired
        private RedisTemplate<String,String> redisTemplate;
    
        @ApiOperation(value = "发送短信的方法")
        @GetMapping("send/{phone}")
        public R sendMsm(@PathVariable String phone) {
            //从redis中获取验证码,如果获取到就直接返回
            String code = redisTemplate.opsForValue().get(phone);
            if (!StringUtils.isEmpty(code)) {
                return R.ok();
            }
            //如果redis获取不到,就进行阿里云发送
            //生成随机值,传递阿里云进行发送
            code = RandomUtil.getFourBitRandom();
            Map<String, Object> param = new HashMap<>();
            param.put("code",code);
            //调用service发送短信的方法
            boolean isSend = msmService.send(param,phone);
            if (isSend){
                //发送成功,把发送成功的验证码放到redis里面
                //设置有效时间
                redisTemplate.opsForValue().set(phone,code,5, TimeUnit.MINUTES);
                return R.ok();
            }else {
                return R.error().message("短信发送失败");
            }
        }
    
    
    
    }
    
    package com.nanjing.msmservice.service;
    
    import java.util.Map;
    
    /**
     * @author yimo
     * @version 1.0
     * @date 2022/3/27 17:20
     */
    public interface MsmService {
        boolean send(Map<String, Object> param, String phone);
    }
    
    package com.nanjing.msmservice.service.impl;
    
    import com.alibaba.fastjson.JSONObject;
    import com.aliyuncs.CommonRequest;
    import com.aliyuncs.CommonResponse;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.http.MethodType;
    import com.aliyuncs.profile.DefaultProfile;
    import com.nanjing.msmservice.service.MsmService;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.stereotype.Service;
    
    import java.util.Map;
    
    /**
     * @author yimo
     * @version 1.0
     * @date 2022/3/27 17:21
     */
    @Service
    public class MsmServiceImpl implements MsmService {
        @Override
        public boolean send(Map<String, Object> param, String phone) {
            if(StringUtils.isEmpty(phone)) {
                return false;
            }
    
            DefaultProfile profile =
                    DefaultProfile.getProfile("default", "LTAI4GAS6zW5Gh6amLaHJBLT", "A0ZKeYdnQw0eWE1hR7BLmq0SOR5OMA");
            IAcsClient client = new DefaultAcsClient(profile);
    
            //设置相关固定的参数
            CommonRequest request = new CommonRequest();//官方例子用的是SendSmsRequest request = new SendSmsRequest();
            //request.setProtocol(ProtocolType.HTTPS);
            request.setMethod(MethodType.POST);
            request.setDomain("dysmsapi.aliyuncs.com");
            request.setVersion("2017-05-25");
            request.setAction("SendSms");
    
            //设置发送相关的参数
            request.putQueryParameter("PhoneNumbers",phone); //手机号
            request.putQueryParameter("SignName","我的xmall购物商城"); //申请阿里云 签名名称
            request.putQueryParameter("TemplateCode",""); //申请阿里云 模板code
            request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param)); //验证码数据,转换json数据传递
    
            try {
                //最终发送
                CommonResponse response = client.getCommonResponse(request);
                boolean success = response.getHttpResponse().isSuccess();
                return success;
            }catch(Exception e) {
                e.printStackTrace();
                return false;
            }
    
        }
    }
    

    本地启动redis

    (实际测试本地不启动redis,主启动类启动也不报错,

    主要是application.properties要去掉多余的Lettuce配置)

    主启动类启动,报错

    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2022-03-27 20:05:36.452 ERROR 15880 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'msmController': Unsatisfied dependency expressed through field 'redisTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stringRedisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stringRedisTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.16.jar:5.3.16]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar:5.3.16]
    	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.10.jar:2.5.10]
    	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.5.10.jar:2.5.10]
    	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:448) [spring-boot-2.5.10.jar:2.5.10]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) [spring-boot-2.5.10.jar:2.5.10]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365) [spring-boot-2.5.10.jar:2.5.10]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) [spring-boot-2.5.10.jar:2.5.10]
    	at com.nanjing.msmservice.MsmApplication.main(MsmApplication.java:17) [classes/:na]
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stringRedisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stringRedisTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.16.jar:5.3.16]
    	... 20 common frames omitted
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.16.jar:5.3.16]
    	... 33 common frames omitted
    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.16.jar:5.3.16]
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.16.jar:5.3.16]
    	... 47 common frames omitted
    Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
    	at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration$LettucePoolingClientConfigurationBuilder.<init>(LettucePoolingClientConfiguration.java:94) ~[spring-data-redis-2.5.9.jar:2.5.9]
    	at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration.builder(LettucePoolingClientConfiguration.java:51) ~[spring-data-redis-2.5.9.jar:2.5.9]
    	at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory.createBuilder(LettuceConnectionConfiguration.java:172) ~[spring-boot-autoconfigure-2.5.10.jar:2.5.10]
    	at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.createBuilder(LettuceConnectionConfiguration.java:110) ~[spring-boot-autoconfigure-2.5.10.jar:2.5.10]
    	at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.getLettuceClientConfiguration(LettuceConnectionConfiguration.java:95) ~[spring-boot-autoconfigure-2.5.10.jar:2.5.10]
    	at org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration.redisConnectionFactory(LettuceConnectionConfiguration.java:77) ~[spring-boot-autoconfigure-2.5.10.jar:2.5.10]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_241]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_241]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_241]
    	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_241]
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.16.jar:5.3.16]
    	... 48 common frames omitted
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_241]
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_241]
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_241]
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_241]
    	... 59 common frames omitted

    解决办法:application.properties去掉多余的Lettuce配置

    重新启动,OK

    swagger测试,测不了,因为个人用不了阿里云短信服务,可惜呀

    展开全文
  • 阿里 oss java源码 一、项目架构图 二、分布式基础概念 1、微服务 微服务架构风格,就像是把一个单独的应用程序开发为一套小服务,每个小服务运行在自己的进程中,并使用轻量级机制通信,通常是 HTTP API。这些...
  • 由于阿里短信现在不对个人客户开放,所以就进行了整合腾讯短信 腾讯整合和视频中逻辑有些差别,网上的教程有限,参考了别人的代码,最大限度的还原视频中的代码 pom.xml <dependencies> <...
  • 服务器nginx配置访问谷粒商城,看不懂可以问,禁止转载
  • 谷粒商城项目案例 一、环境准备 1、安装Linux虚拟机 CentOS或ubuntu 可以使用echo $LANG看服务器语言,uname查看系统命 2、安装docker 1、容器技术,可以快速搭建mysql、redis等应用。 2、仓库地址: 3、官方文档: ...
  • 谷粒学院(八)阿里oss | 头像上传 | Nginx
  • 谷粒学院 讲师详细页 一、后端部分 1、TeacherFrontController @RestController @CrossOrigin @RequestMapping("/eduservice/teacherFront") public class TeacherFrontController { @Autowired private ...
  • 谷粒学院(十五)JWT | 阿里短信服务 | 登录与注册前后端实现
  • 谷粒商城 使用服务器和内网穿透实现 Nginx域名访问 (P139-P40), 由于本人使用的是腾讯服务器,Nginx跑在服务器上,这里通过使用**花生壳**内网穿透 + 腾讯 Nginx 来实现
  • //上传视频到阿里 @PostMapping("uploadAliyunVideo") public R uploadAliyunVideo(MultipartFile file) { //返回上传之后的视频唯一id String videoId = vodService.uploadVideoAly(file); return R.ok().data(...
  • 存储开通与使用 SpringCloudAlibaba-OSS 阿里对象存储 SDK管理文件 网址:阿里帮助中心-阿里,领先的云计算服务提供商 (aliyun.com) 安装SDK(在gulimall-product的pom.xml中) <dependency&...
  • 一、开通阿里对象存储OSS 二、创建bucket 三、创建操作阿里OSS许可证 四、用代码实现头像上传功能 五、引入相关依赖 六、创建properties配置文件 七、创建主启动类 八、启动测试一下 九、创建常量类,...
  • 按照阿里官方设置坐标,报错,因为aliyun-java-vod-upload还未开源,需要到 到官网下载SDK 是一个压缩包 复制jar包 根据网上的解决办法复制到apache-maven-3.5.2\bin目录下 cmd执行安装 mvn install:install-file...
  • 3.开通阿里短信服务 4.在service_msm中引入依赖 5.controller 复制工具类RandomUtil 6.service 但是现在阿里短信服务的申请条件变高了。项目没有上线的话申请不到。 我也申请失败了。 所以这个模块的...
  • 谷粒在线教育》整合阿里VOD视频点播实现上传 注意事项:要想使用阿里开通视频点播啊,必须实名认证 第一步:进入阿里官网 https://www.aliyun.com/ 第二步:进入视频点播控制台 第三步:点击管理控制台...
  • 阿里视频点播 视频点播(ApsaraVideo for VoD)是集音视频采集、编辑、上传、自动化转码处理、媒体资源管理、分发加速于一体的一站式音视频点播解决方案。 在service下面新建service_vod模块 依赖 <...
  • 一、课程最终发布 – 后端 1、实体类 2、编写Controller类 3、编写Service类 由于我们最终发布页面显示的数据是来源于四张表,所以我们需要手动写SQL语句实现。...4、编写mapper类xml配置文件 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,862
精华内容 744
关键字:

云谷粒