谷粒学苑项目问题解决

博客内容涉及多个编程异常的解决,包括跨域问题、前端类型检查错误、数据库配置失败、HTTP错误代码如403、413等,还涵盖了Spring Boot、MyBatis、Nacos服务注册、Nuxt.js依赖下载、阿里云视频点播、Nginx配置、Mysql数据截断异常等技术问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

跨域问题

Access to XMLHttpRequest at ‘http://localhost:9001/eduservice/user/login’ from origin ‘http://localhost:9528’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

image-20211225230032050

原因:

通过一个地址去访问另外一个地址,这个过程中如果有三个地方任何一个不一样

访问协议 http https
ip地址 192.168.1.1 202.168.11.11
端口号 8080 9528

解决办法:

(1)在后端接口Controller 添加注解 @CrossOrigin (常用)

@CrossOrigin  //解决跨域
public class EduLoginController {
   }

(2)使用网关解决

Invalid prop: type check failed for prop “min“. Expected Number, got String

在这里插入图片描述

min 改成 :min 带冒号
在这里插入图片描述

错误原因:min max 之类,使用组件的话应为 :min :max

Uncaught (in promise) cancel

原因:

this.$confirm方法内置promise方法,
所以不能把.catch()去掉(因为取消操作时,无法捕获)   

解决办法:
在this.$confirm方法后加上.catch方法即可,注意要写上空方法体

.catch(()=>{
   });

在这里插入图片描述

在 created 的方法中清空表单失效

多次路由跳转到同一个页面,在页面中 created 方法只会执行第一次,后面在进行跳转不会执行的

解决办法: 使用 侦听器

  //监听
  watch: {
   
    //路由变化方式,路由发生变化,方法就会执行
    $route(to, from) {
   
      console.log("watch $route");
      this.init();
    },
  },
  //页面渲染之前执行
  created() {
   
    this.init();
  },
  methods: {
   
    init() {
   
      //判断路径是否有id值
      if (this.$route.params && this.$route.params.id) {
   
        //从路径获取id值
        const id = this.$route.params.id;
        //调用根据id查询的方法
        this.getInfo(id);

        //没有id 做添加
      } else {
   
        this.teacher = {
   };
      }
    },
 }

Failed to configure a DataSource

Description:

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,

而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,又因为项目(oss模块)中并没有关于dataSource相关的配置信息,所以当spring创建dataSource bean时因缺少相关的信息就会报错。

解决办法:

方法1、在@SpringBootApplication注解上加上exclude,解除自动加载DataSourceAutoConfiguration

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

403

CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

image-20211226165624429

原因:

  1. 跨域
  2. 路径资源不存在(路径写错了)

添加课程重置表单时二级联动和课程封面失效

解决办法:

不能直接令 this.courseInfo = {} 这样会清空属性和值, 也就是说要保留属性令值为空即可

而应使用默认值

this.courseInfo = {
   
          title: "",
          subjectId: "",
          subjectParentId: "", //一级分类
          teacherId: "",
          lessonNum: 0,
          description: "",
          cover: "/static/weixinpay.jpg",
          price: 0,
        },

重置表单时富文本没有重置

org.apache.ibatis.binding.BindingException

Invalid bound statement (not found): com.example.serviceedu.mapper.EduCourseMapper.selectCoursePublishVoById

AbstractHandlerExceptionResolver.java:194 |org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver |Resolved exception caused by handler execution: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.edu.mapper.CourseMapper.getCoursePublishVoById

原因:

  1. Mapper 接口的方法名 与 Mapper接口的映射文件(xxx.xml) 的 id 不一样

    image-20211230234923498

  2. dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所有资源文件是不发布到target目录下的,

    image-20220321001223547

    解决方案:

    1、在guli_edu的pom中配置如下节点

    <!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
    

    重新打包项目会发现target目录下出现了xml文件夹

    img

    2、在Spring Boot配置文件中添加配置

    #配置mapper xml文件的路径
    mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml
    

Exception in thread “main” com.aliyuncs.exceptions.ClientException: Forbidden.AliyunVoDEncryption

Exception in thread “main” com.aliyuncs.exceptions.ClientException: Forbidden.AliyunVoDEncryption : Currently only the AliyunVoDEncryption stream exists, you must use the Aliyun player to play or set the value of ResultType to Multiple.

原因: 试图获取加密视频的地址

解决: 换一个没有加密的文件就可以了

FileSizeLimitExceededException

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

文件大小限制超过异常

解决:

application.properties 设置上传文件的大小

# 最大上传单个文件大小:默认1M
spring.servlet.multipart.max-file-size=1024MB
# 最大置总上传的数据大小 :默认10M
spring.servlet.multipart.max-request-size=1024MB

413 (Request Entity Too Large)

请求体过大

配置nginx上传文件大小,否则上传时会有 413 (Request Entity Too Large) 异常

打开nginx主配置文件nginx.conf,找到http{},添加

client_max_body_size 1024m;

重启nginx

nginx -s reload

no server available

原因: 引入了服务注册的依赖,没有在启动类添加 @EnableDiscoveryClient 注解

<!--服务注册-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

服务注册的步骤:

①: 配置Nacos客户端的pom依赖

<!--服务注册-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

②: 添加服务配置信息

配置application.properties,在客户端微服务中添加注册Nacos服务的配置信息

# nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

③: 添加Nacos客户端注解 在客户端微服务启动类中添加注解

@EnableDiscoveryClient

nuxt依赖下载失败,npm WARN Invalid name: “{ { name }}“

找到package.json文件,在里面修改即可

img

img

Error: Could not compile templa

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暗恋花香

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值