Springboot+Vue/React项目遇到的一些bug

mybatisX的方法使用不了

问题:mybatis-plus 的 save() 方法不能使用,说没有这个方法

在这里插入图片描述

原因:版本问题,原来使用的是mybatis-plus:3.5.2版本,这个版本好像有bug

解决方法:更新至最新版本3.5.3即可

500(Internal Server Error)

问题:启动后端项目,报错:2023-05-03T14:38:05.334+08:00 ERROR 18108 — [nio-8082-exec-6] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/api] threw exception [Request processing failed: com.example.usercenter.exception.BusinessException: 请求参数错误] with root cause com.example.usercenter.exception.BusinessException: 请求参数错误(这里的请求参数错误是我自己写的异常类的异常信息)

在这里插入图片描述

原因:改了代码/前端代码,重新启动后端项目也不行

解决方法:Build/Rebuild,在项目中改了一些代码,出现以上问题,如果没有其他明显的错误,可以rebuild一下试试。(引入了没有用的依赖也有可能,不过这次不是这个原因)

Vue项目前端页面空白

问题:启动前端Vue项目后,页面空白
在这里插入图片描述

原因:App.vue 中忘了添加顶级路由 <router-view/>

解决方法:在 APP.vue 中添加路由标签,注册路由组件

<div id="content">
    <router-view />
</div>

跨域问题

问题:Access to XMLHttpRequest at ‘http://localhost:8082/api/user/login’ from origin ‘http://127.0.0.1:5173’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: The value of the ‘Access-Control-Allow-Credentials’ header in the response is ‘’ which must be ‘true’ when the request’s credentials mode is ‘include’. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

原因:常见的跨域问题

解决方法:在后端项目添加跨域配置

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfg implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //设置允许跨域的路径
        registry.addMapping("/**")
                //设置允许跨域请求的域名
                //当**Credentials为true时,**Origin不能为星号,需为具体的ip地址【如果接口不带cookie,ip无需设成具体ip】
                .allowedOrigins("http://localhost:9527", "http://127.0.0.1:9527", "http://127.0.0.1:8082", "http://127.0.0.1:8083")
                //是否允许证书 不再默认开启
                .allowCredentials(true)
                //设置允许的方法
                .allowedMethods("*")
                //跨域允许时间
                .maxAge(3600);
    }
}

dubbo依赖冲突

问题:启动Spring Cloud的gateway项目时报错:Error starting ApplicationContext. To display the condition evaluation evaluation report re-run your application with ‘debug’ enabled.
APPLICATION FAILED TO START
Description:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.
Action:
Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.

在这里插入图片描述

原因:dubbo版本过低

解决方法(任选一种,哪种可以选哪种):

  1. gateway的pom文件上注释掉spring-boot-starter-web代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
  1. 在配置文件上加上
spring:
    main:
        web-application-type: reactive

mybatis依赖冲突

问题:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.momo.apibackend.mapper.UserMapper.selectCount

原因:依赖引入错误,引成下面的:

  	<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>3.0.1</version>
		</dependency>
	<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-extension</artifactId>
			<version>3.5.3.1</version>
	</dependency>

解决方法:把上述两个mybatis相关的依赖改成下面的:

  	<dependency>
		<groupId>org.mybatis.spring.boot</groupId>
		<artifactId>mybatis-spring-boot-starter</artifactId>
		<version>3.0.0</version>
	</dependency>
	<dependency>
		<groupId>com.baomidou</groupId>
		<artifactId>mybatis-plus-boot-starter</artifactId>
		<version>3.5.3.1</version>
	</dependency>

子项目的sdk类加载不出来

问题:多模块(子项目)项目,根项目调用其他模块(子项目)的sdk类时报错:WARN: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘interfaceInfoController’: Injection of resource dependencies failed

在这里插入图片描述

原因:在根项目中引用了其他项目包下的bean,但找不到

解决方法:需要在启动类加上以下配置,让spring去扫描包,即sdk所在的包

@SpringBootApplication(scanBasePackages = {"com.momo.apiclientsdk","com.momo.apibackend"})

后端接口文档(swagger+knife4j)打不开

问题:使用 swagger+knife4j 生成接口文档,在浏览器输入接口文档路径 http://localhost:xxx/xxx/doc.html 打开报错:在这里插入图片描述

原因:swagger+knife4j 依赖引入错误(原来引的什么忘了)

解决方法:引入以下依赖(只需引入knife4j,不需要引入swagger):

	<!--添加swagger的依赖-->
	<dependency>
		<groupId>com.github.xiaoymin</groupId>
		<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
		<version>4.1.0</version>
	</dependency>

同时要在配置文件application.yml中添加配置:

springdoc:
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha
  api-docs:
    path: /v3/api-docs
  group-configs:
    - group: 'default'
      paths-to-match: '/**'
      packages-to-scan: com.momo.apibackend.controller # 生成controller层的接口

knife4j:
  enable: true
  setting:
    language: zh_cn
    swagger-model-name: 实体类列表

持续添加…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值