创建认证模块

image.png
image.png

pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <artifactId>guli-mall</artifactId>
  7. <groupId>com.zsy</groupId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. </parent>
  10. <artifactId>mall-auth-server</artifactId>
  11. <version>0.0.1-SNAPSHOT</version>
  12. <name>mall-auth-server</name>
  13. <description>认证服务(社交登录、Oauth2.0、单点登录)</description>
  14. <dependencies>
  15. <dependency>
  16. <groupId>com.zsy</groupId>
  17. <artifactId>mall-common</artifactId>
  18. <exclusions>
  19. <exclusion>
  20. <groupId>com.baomidou</groupId>
  21. <artifactId>mybatis-plus-boot-starter</artifactId>
  22. </exclusion>
  23. </exclusions>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-devtools</artifactId>
  32. <scope>runtime</scope>
  33. <optional>true</optional>
  34. </dependency>
  35. </dependencies>
  36. </project>

application.yaml

  1. spring:
  2. application:
  3. name: mall-auth-server
  4. cloud:
  5. nacos:
  6. discovery:
  7. server-addr: 192.168.163.131:8848
  8. thymeleaf:
  9. cache: false
  10. server:
  11. port: 20000

主启动类

  1. package com.zsy.auth;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  5. import org.springframework.cloud.openfeign.EnableFeignClients;
  6. /**
  7. * @author ZSY
  8. */
  9. @EnableFeignClients
  10. @EnableDiscoveryClient
  11. @SpringBootApplication
  12. public class MallAuthServerApplication {
  13. public static void main(String[] args) {
  14. SpringApplication.run(MallAuthServerApplication.class, args);
  15. }
  16. }

启动验证

启动服务,发现服务注册进 Nacos
image.png

页面及域名访问初始化

修改hosts实现域名访问

  1. # guli mall #
  2. 192.168.163.131 gulimall.com
  3. 192.168.163.131 search.gulimall.com
  4. 192.168.163.131 item.gulimall.com
  5. 192.168.163.131 auth.gulimall.com

配置网关转发域名

  1. - id: mall_auth_route
  2. uri: lb://mall-auth-server
  3. predicates:
  4. - Host=auth.gulimall.com

引入登录页面

将资料高级篇登录页面和注册页面放到 templates 下,静态文件可以选择 Nginx 动静分离配置,这里采用直接引用的方式。最终目录:
image.png