当前位置: 首页 > 工具软件 > 拾壹博客 > 使用案例 >

拾壹博客的启动及一些注意事项

佘俊茂
2023-12-01

一.后端(blog)启动报错项以及注意事项:


1.后台如果使用JDK17启动会报错:

Caused by: java.lang.NullPointerException: Cannot invoke “Object.hashCode()” because “key” is null

----修改成1.8启动即可解决(作者使用的是1.8)

注意事项:

  1. 正常来说修改application.yml中的数据库链接与密码,即可启动成功

  1. sql脚本执行之前一定要确保没有乱码,否则启动页面会乱码 (我使用DBeaver,把脚本先复制到一个SQL编辑器里面,确保没乱码再执行)

  1. 如需上传文件保存至本地(例如相册的照片),需执行以下操作:
    3.1 启动项目后第一时间把 “系统配置”–》“系统配置” 中的文件保存先切换至本地保存

3.2 “系统配置”–》“本地文件存储” 中的本地文件域名修改为 http://localhost:8800/jpg/ (项目路径/jpg ,这个jpg对应下面新增JpgPathConfig.java文件中配置的虚拟路径)


3.3 application.yml中把 upload-folder上传照片的路径修改成本地实际上传路径:

     file:
upload-folder:D:/jpg/#本地上传照片,最后一定要有/,否则文件无法找到

3.4 新增配置文件JpgPathConfig.java:

package com.shiyi.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ConfigurationpublicclassJpgPathConfigimplementsWebMvcConfigurer {

    @Value("${file.upload-folder}")//本地上传文件的路径private String UPLOAD_FOLDER;

    @OverridepublicvoidaddResourceHandlers(ResourceHandlerRegistry registry) {
	//   虚拟路径/jpg/对应系统配置中本地文件域名的后缀,
        registry.addResourceHandler("/jpg/**").addResourceLocations("file:" + UPLOAD_FOLDER);
	//把实际上传路径映射到虚拟路径中(当前项目/jpg/),当谷歌浏览器访问虚拟路径就可以看到该文件了
    }
}

也就是说把上传的真实路径 D:/jpg/映射到项目静态文件的jpg文件夹,前台展示的文件url就是http://localhost:8800/jpg/**


后来发现WebMvcConfig.java中已经有定义有:
registry.addResourceHandler("/img/**").addResourceLocations("file:" + UPLOAD_FOLDER);
也就是只需要执行3.3修改application.yml中实际存放的图片路径即可,页面只需要在img标签中使用/img/xxx.jpg即可直接访问图片(注意拦截器中是拦截访问/img/**路径下才会被转到图片的实际路径中


4 . pom.xml把log4j的依赖删除,因为使用了logback,并没有使用log4j,启动会一直警告没有配置log4j,

5. 第4步执行完之后,再替换application.yml中的spring.datasource.filters: stat,wall,slf4j #log4j 因为未使用log4j依赖,因此使用slf4j来替换log4j(因为log4j依赖已被删除,因此必须使用logback的slf4j来替换log4j,否则启动报错)


二. 前端前台(blog-web)启动注意事项:


1. shiyi-blog-master\blog-web(前台的前端)根目录下打开cmd ,运行 npm install --registry=https://registry.npmmirror.com ,依赖安装完毕,使用npm run serve 启动测试环境,如果有以下报错信息:

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

执行npm i vue-template-compiler@2.7.14 --save ,2.7.14对应的是当前试用的vue的版本,意思是把某个依赖的版本升级到vue2.7.14对应的版本,再次启动项目,如果还是报错,那么就直接执行npm audit fix --registry=https://registry.npmmirror.com 来修复各依赖的版本,使其对应vue2.7.14的版本修复完毕再次启动项目

~ ------这次启动(npm run serve)成功,访问:http://localhost:80/就好了~


三. 前端后台(blog-admin)启动注意事项:


报错信息:

PS D:\hewenjun\shiyi-blog-master\blog-admin> npm install --registry=https://registry.npmmirror.com
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: sass-loader@8.0.2
npm ERR! Found: node-sass@6.0.1
npm ERR! node_modules/node-sass
npm ERR! dev node-sass@"^6.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional node-sass@"^4.0.0" from sass-loader@8.0.2
npm ERR! node_modules/sass-loader
npm ERR! dev sass-loader@"^8.0.2" from the root project
npm ERR!
npm ERR! node_modules/node-sass
npm ERR! peerOptional node-sass@"^4.0.0" from sass-loader@8.0.2
npm ERR! node_modules/sass-loader
npm ERR! dev sass-loader@"^8.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

解决办法:

npm uninstall sass-loader node-sass 卸载掉

打开package.json文件把"sass-loader": "^8.0.2"版本修改成7.3.1,再次执行npm install --registry=https://registry.npmmirror.com

这次搞定,启动成功访问:http://localhost:9528/就好了 ,虽然还有很多报错信息,但也启动成功,注意启动方法是npm run dev,而不是前台的npm run serve否则无法启动成功

npm notice
npm notice New major version of npm available! 8.19.2 -> 9.6.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.6.2
npm notice Run npm install -g npm@9.6.2 to update!
npm notice

那就升级npm

npm install -g npm@9.6.2 ------升级后就ok了


2023-03-20 19:09:50.961 [main] ERROR com.alibaba.druid.pool.DruidDataSource:918 - init datasource error, url: jdbc:mysql://127.0.0.1:3306/blog?characterEncoding=UTF-8&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&tinyInt1isBit=false
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:118)
at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:764)
at com.alibaba.druid.filter.FilterEventAdapter.connection_connect(FilterEventAdapter.java:33)
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:112)
at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:764)
  allowPublicKeyRetrieval=true   #数据源添加这句上去就ok
 url: jdbc:mysql://127.0.0.1:3306/blog?allowPublicKeyRetrieval=true

注意:npm run build 打包后台 ,跟ruoyi打包命令(npm run build:prod)不一样

------------------------------------------------------------------------------------

DruidConfig.java中有配置druid数据库监控页的账号密码,因数据库连接池未使用druid,因此单独配置的

 类似资料: