一.后端(blog)启动报错项以及注意事项:
1.后台如果使用JDK17启动会报错:
Caused by: java.lang.NullPointerException: Cannot invoke “Object.hashCode()” because “key” is null
----修改成1.8启动即可解决(作者使用的是1.8)
注意事项:
正常来说修改application.yml中的数据库链接与密码,即可启动成功
sql脚本执行之前一定要确保没有乱码,否则启动页面会乱码 (我使用DBeaver,把脚本先复制到一个SQL编辑器里面,确保没乱码再执行)
如需上传文件保存至本地(例如相册的照片),需执行以下操作:
a. 启动项目后第一时间把 “系统配置”–》“系统配置” 中的文件保存先切换至本地保存
b. “系统配置”–》“本地文件存储” 中的本地文件域名修改为 http://localhost:8800/jpg/ (项目 路径/jpg ,这个jpg对应下面新增JpgPathConfig.java文件中配置的虚拟路径)
c. application.yml中把 upload-folder上传照片的路径修改成本地实际上传路径:
file:
upload-folder:D:/jpg/#本地上传照片,最后一定要有/,否则文件无法找到
d. 新增配置文件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/**
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否则无法启动成功