创建认证模块

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

spring:
  application:
    name: mall-auth-server
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.163.131:8848
  thymeleaf:
    cache: false
server:
  port: 20000

主启动类

package com.zsy.auth;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
 * @author ZSY
 */
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class MallAuthServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(MallAuthServerApplication.class, args);
    }
}

启动验证

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

页面及域名访问初始化

修改hosts实现域名访问

# guli mall #
192.168.163.131        gulimall.com
192.168.163.131        search.gulimall.com
192.168.163.131        item.gulimall.com
192.168.163.131        auth.gulimall.com

配置网关转发域名

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

引入登录页面

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