目录




-
- <dependency>
- <groupId>com.github.xiaoymingroupId>
- <artifactId>knife4j-spring-boot-starterartifactId>
- <version>3.0.2version>
- dependency>
在 WebMvcConfig 类上加上两个注解
- @EnableSwagger2
- @EnableKnife4j
然后添加两个方法
- @Bean
- public Docket createRestApi() {
- // 文档类型
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.itheima.reggie.controller"))
- .paths(PathSelectors.any())
- .build();
- }
-
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title("瑞吉外卖")
- .version("1.0")
- .description("瑞吉外卖接口文档")
- .build();
- }
在 WebMvcConfig 类的 addResourceHandlers 配置静态资源映射
- registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
- registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
在 LoginCheckFilter 类的 doFilter 方法添加放行路径
- // knife4j 放行路径
- "/doc.html",
- "/webjars/**",
- "/swagger-resources",
- "/v2/api-docs"
在浏览器访问 http://localhost:8080/doc.html ,可以看到接口文档


192.168.44.128:主从复制的主库、redis、nginx
192.168.44.127:主从复制的从库
① 将资料中前端打包后的文件 dist 传到 nginx 根目录下的 html 目录
② 修改 nginx.conf
- server{
- listen 80;
- server_name localhost;
-
- location / {
- root html/dist; # 根目录
- index index.html; # 默认首页
- }
-
- # 反向代理
- location ^~ /api/ {
- rewrite ^/api/(.*)$ /$1 break; # rewirte:重写url,将 /api/ 除去
- proxy_pass proxy_pass http://192.168.44.128:8080;
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html{
- root html;
- }
- }
① 在服务器安装 jdk、git、maven、MySQL,使用 git 将项目克隆下来
git clone http://...
然后使用 maven 将项目打包
mvn clean package -Dmaven.test.skip=true
② 将资料中的 reggieStart.sh 自动部署脚本导入,这里稍作修改,将这里的目录改为自己存放的位置
- echo 准备从Git仓库拉取最新代码
- cd /usr/local/javaapp/reggie
然后授予能够执行 sh 脚本的权限
chmod 777 reggieStart.sh
③ 执行 sh 脚本文件
./reggieStart.sh
若这里每次从 git 拉取代码都需要输入账号密码,可以输入下面的命令
git config --global credential.helper store
在 application.yml 中将图片路径修改为可用路径
- reggie:
- path: /usr/local/javaapp/reggie_img
然后将图片上传到该路径即可