mall developing

Bug shooting

Bug1.

captcha disappearance

https://www.javazxz.com/thread-7116-1-1.html

Bug2.

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

network problem. The student.gla.ac.uk network filed cannot access to tencent server.

Bug3.

No spring.config.import property has been defined

产生问题的原因是bootstrap.properties比application.properties的优先级要高
由于bootstrap.properties是系统级的资源配置文件,是用在程序引导执行时更加早期配置信息读取;
而application.properties是用户级的资源配置文件,是用来后续的一些配置所需要的公共参数。
但是在SpringCloud 2020.* 版本把bootstrap禁用了,导致在读取文件的时候读取不到而报错,所以我们只要把bootstrap从新导入进来就会生效了。

1
2
3
4
5
<dependency>
<groupId>org.springframework.clouds</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.3</version>
</dependency>

在全部使用nacos配置后,就不用引用这个了

Bug4

java: 找不到符号 符号:方法 XXX() 位置: 类型为io.renren.modules.sys.entity

Solution:

  1. 这是因为你的idea中内置lombok和项目中pom文件的版本不兼容的原因,简单说就是这两个发生冲突了,大部分的出现在idea2020和2021版本上可能会出现问题。
  2. 因为lombok版本是一般是受springboot版本管理的,也可以通过升级springboot的版本来提高lombok版本,只要你springboot中引用的Lombok高于上面的版本就可以。
1
2
3
4
5
6
7
8
<!--Lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.14</version>
<scope>provided</scope>//注意这行代码一定要加上去,我的问题就是出现在没有加这行代码还是会报错、
</dependency>

Config:

1. redis

Remote configuration:![image-20230403164112175](/Users/joshua/Library/Application Support/typora-user-images/image-20230403164112175.png)

mysql

![image-20230403164158804](/Users/joshua/Library/Application Support/typora-user-images/image-20230403164158804.png)

![image-20230403164227851](/Users/joshua/Library/Application Support/typora-user-images/image-20230403164227851.png)

JDBC

Info:

Url:jdbc:mysql://47.98.63.250:3306/mall_pms

use the server’s public ip addr

DBMS: MySQL (ver. 5.7.41)
Case sensitivity: plain=exact, delimited=exact
Driver: MySQL Connector/J (ver. mysql-connector-java-8.0.25 (Revision: 08be9e9b4cba6aa115f9b27b215887af40b159e0), JDBC4.2)

Ping: 1 sec, 25 ms
SSL: yes

nacos:

nacos配置按照最新版本的springcloud alibaba来

不用使用bootstrap的配置文件来定位nacos

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<!-- 排除 bootstrap, 未来版本 spring-cloud-alibaba 应该在 spring boot >= 2.4.0 时将该依赖设置为 optional -->
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</exclusion>
</exclusions>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
spring:
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
namespace: 2e40d043-66f9-4a92-acc1-af90e80b9204
group: dev
config:
import:
- optional:nacos:mall-coupon.yml?group=dev # 监听 DEFAULT_GROUP:mall-coupon.yml覆盖默认 group, 监听 group_01:test01.yml
- optional:nacos:datasource.yml?group=dev&refreshEnabled=false # 不开启动态刷新
- optional:nacos:mybatis.yml?group=dev
- optional:nacos:other.yml?group=dev

容器重启数据丢失问题:

MySQL 配置

1
vi /mydata/mysql/conf/my.cnf 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[client] 

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

init_connect='SET collation_connection = utf8_unicode_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_unicode_ci

skip-character-set-client-handshake

skip-name-resolve
1
2
3
4
5
6
7
8
9
docker run -p 3306:3306 \
--name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql/my.cnf \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7


通过容器的 mysql 命令行工具连接

1
docker exec -it mysql mysql -uroot -proot

设置 root 远程访问

1
2
3
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; 

flush privileges;
1
2
3
4
docker exec -it mysql /bin/bash

cd /etc/mysql
ls

解决方法
了解上面的介绍后,解决它就很简单了。

1
2
docker ps -a 找到我们上次运行的容器id
docker restart id 即可

你没看错就这样就完了。

我这里创建了volume容器来对其进行持久化,位置在/var/lib/docker/volumes/mysql-data/_data,从mysql容器中mount在我的cloud server上的路径为my/own

Gateway

将renren-fast注册到nacos中去, 可能会遇到一些依赖错误,在该微服务的pom文件中引入这两个坐标

1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>3.1.5</version> <!-- Make sure to use the correct version -->
</dependency>

在gateway中按格式加入

1
2
3
4
5
6
- id: admin_route
uri: lb://renren-fast # 路由给renren-fast,lb代表负载均衡
predicates: # 什么情况下路由给它
- Path=/api/** # 默认前端项目都带上api前缀,
filters:
- RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}

Cors

记得将renren-fast中的cors注解掉

并在网关中配置这个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.josh.mall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
* Description:
* Author: joshua
* Date: 2023/5/28
*/
@Configuration // gateway
public class MallCorsConfiguration {

@Bean // 添加过滤器
public CorsWebFilter corsWebFilter(){
// 基于url跨域,选择reactive包下的
UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
// 跨域配置信息
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 允许跨域的头
corsConfiguration.addAllowedHeader("*");
// 允许跨域的请求方式
corsConfiguration.addAllowedMethod("*");
// 允许跨域的请求来源
corsConfiguration.addAllowedOriginPattern("*");
// 是否允许携带cookie跨域
corsConfiguration.setAllowCredentials(true);

// 任意url都要进行跨域配置
source.registerCorsConfiguration("/**",corsConfiguration);
return new CorsWebFilter(source);
}
}

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2021-2024 Mingwei Li
  • Visitors: | Views:

Buy me a bottle of beer please~

支付宝
微信