谷粒商城踩坑及解决

谷粒商城项目总结

day1

1.由于springboot强制创建版本为3.X.X而3.X.X要求的jdk最低版本是17

集成人人开源来新建后台管理系统时,出现各种报错

必须降低jdk版本,其中最简单的方法是直接修改版本为2.X.X

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.8</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

2.再次遇到数据库被攻击索要比特币

在云服务器修改了mysql密码,但是只在云服务器上生效,使用navicat连接时,还是密码不变

解决方法是在xshell中执行新版命令

USE mysql;
UPDATE USER SET authentication_string=PASSWORD('123') WHERE USER='root' AND HOST='%';
FLUSH PRIVILEGES;

3.前端运行npm install报错,解决方案

运行以下命令,再重新运行npm install

npm install chromedriver@2.46.0 --ignore-scripts

4.遇到了循环依赖问题

报错如下

The dependencies of some of the beans in the application context form a cycle:
​
┌──->──┐
|  com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
└──<-──┘
​
​
Action:
​
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true

com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration 相关。循环依赖意味着两个或多个 Spring Bean 互相依赖,形成了一个闭环,导致 Spring 容器无法决定哪个 Bean 先实例化。

解决循环依赖问题

解决循环依赖的关键在于重新设计应用的结构和 Bean 的依赖关系,以避免循环。以下是一些可能的解决方法:

  1. 重构代码以消除循环依赖

    • 检查涉及循环依赖的 Bean,并考虑是否可以通过重新设计来消除循环。可能的方法包括合并 Bean、更改 Bean 的注入方式(如从构造器注入改为 setter 注入或字段注入),或引入新的 Bean 来分离职责。

  2. 使用 @Lazy 注解

    • 在依赖注入点使用 @Lazy 注解可以延迟 Bean 的加载,从而避免循环依赖。这可以用于 setter 注入或字段注入。

  3. 使用 Setter 注入

    • 如果您当前使用构造器注入,考虑更改为 setter 注入。Spring 容器可以处理 setter 注入的循环依赖。

  4. 检查第三方配置

    • 由于错误涉及 PageHelperAutoConfiguration,这可能是由第三方库或其自动配置引起的。检查是否有相关配置或使用方式导致了循环依赖,或者查阅相关文档以了解是否有已知问题或解决方案。

作为最后的手段

Spring 提供了一个属性 spring.main.allow-circular-references,您可以将其设置为 true 来允许循环依赖。但这只是一种权宜之计,不建议长期依赖:

  • application.properties

    application.yml

    中设置:

    propertiesCopy code
    spring.main.allow-circular-references=true

注意事项

  • 长期依赖于 Spring 的循环依赖支持可能会隐藏设计上的问题,最好是通过重新设计来解决这些问题。

  • 在使用 @Lazy 或更改注入方式之前,确保理解这些改变对应用的潜在影响。

解决循环依赖方法尝试

1.通用方法,设置允许循环依赖 这个方法在这里是无效的

@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@MapperScan("io.renren.dao")
public class RenrenApplication {
​
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(RenrenApplication.class);
        springApplication.setAllowCircularReferences(Boolean.TRUE);
        SpringApplication.run(RenrenApplication.class, args);
    }
}

2.尝试提高pagehelper版本

<pagehelper.spring.boot.version>2.1.0</pagehelper.spring.boot.version>

maven仓库访问地址:Maven Central Repository Search

在maven仓库里面找到合适的版本进行更改,尝试后成功。

项目能运行但是页面出错

image-20240111175304643

解决办法是修改yaml文件为如下格式 修改后成功运行

web:
    resources:
      static-locations: classpath:/static/, classpath:/views/

day2

1.运行测试类报错1

java.lang.Exception: No runnable methods
​
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)

这是导包错误的原因,正确的测试包是

import org.junit.Test;

2.踩坑日记:由于我的mysql服务器部署在云服务器上,导致一直无法连接上mysql服务器,报错如下

he last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
### The error may exist in com/atguigu/gulimall/product/dao/BrandDao.java (best guess)
### The error may involve com.atguigu.gulimall.product.dao.BrandDao.insert
### The error occurred while executing an update
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
​
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
    ... 76 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
​
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
    at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
    at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.prepareStatement(MybatisSimpleExecutor.java:93)
    at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:53)
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
    ... 82 more
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
​
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
    ... 90 more
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
​
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
    at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
    at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:338)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.negotiateSSLConnection(NativeAuthenticationProvider.java:777)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:486)
    at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:202)
    at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1340)
    at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
    ... 103 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:172)
    at java.base/sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:103)
    at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:247)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:448)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426)
    at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316)
    at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188)
    at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99)
    at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:329)
    ... 110 more
​

根本原因是ssl握手失败,可能是服务器端和客户端支持的ssl/tls版本不兼容

缺少或无效的ssl证书

服务器或客户端配置不正确

解决办法是,配置jdbc url来禁用ssl 禁用后运行成功!

url: jdbc:mysql://121.41.36.146:3306/gulimall_pms?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8

人人开源自动生成各个微服务

在renren-generator-master模块

1.要修改模块名和数据表名的前缀

image-20240112160217977

2.修改配置文件yaml中要连接的数据库

image-20240112160339491

运行这个模块自动生成相应的crud代码 替换目标模块的main文件 并修改yaml文件要连接的数据库名

image-20240112160535873

常见问题之端口占用:

报错

***************************
APPLICATION FAILED TO START
***************************
​
Description:
​
Web server failed to start. Port 10000 was already in use.
​
Action:
​
Identify and stop the process that's listening on port 10000 or configure this application to listen on another port.
​
2024-01-12 16:26:30.865  INFO 21620 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
​
Process finished with exit code 1
​

找出并停止占用端口的进程

  1. 在Windows上

    • 打开命令提示符(cmd)。

    • 输入命令 netstat -ano | findstr :10000。这将显示监听端口10000的进程的ID。

    • 使用任务管理器或命令 taskkill /PID [进程ID] /F 去终止该进程。替换 [进程ID] 为你在上一步找到的ID。

  2. 在Linux或macOS上

    • 打开终端。

    • 输入命令 lsof -i :10000netstat -tulnp | grep :10000(某些Linux发行版可能需要安装net-tools)来找出占用端口的进程。

    • 使用 kill [进程ID]kill -9 [进程ID] 命令结束该进程。替换 [进程ID] 为找到的ID。

C:\Users\86159>netstat -ano | findstr :10000
  TCP    127.0.0.1:10000        0.0.0.0:0              LISTENING       21532
​
C:\Users\86159>taskkill /PID 21532 /F
成功: 已终止 PID 为 21532 的进程。
​
C:\Users\86159>

常见问题之数据库和java实体类映射错误

java: 找不到符号
  符号:   类 Longblob
  位置: 类 com.atguigu.gulimall.ware.entity.UndoLogEntity

如果你是想使用MySQL的LONGBLOB数据类型,记住在Java中并没有直接对应的Longblob类。通常,大型的二进制数据在Java中使用byte[]类型来表示。如果你是在JPA实体中使用它,你可能需要用@Lob注解来标记该字段,例如:

javaCopy codeimport javax.persistence.Lob;
​
// ...
​
@Lob
private byte[] yourBlobField;

这里的@Lob注解表明这个字段应该被映射为数据库中的大对象类型,比如BLOBCLOB

nacos启动命令

startup.cmd -m standalone
  • 25
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值