创建认证模块
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>guli-mall</artifactId>
<groupId>com.zsy</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>mall-auth-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mall-auth-server</name>
<description>认证服务(社交登录、Oauth2.0、单点登录)</description>
<dependencies>
<dependency>
<groupId>com.zsy</groupId>
<artifactId>mall-common</artifactId>
<exclusions>
<exclusion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
</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);
}
}
启动验证
页面及域名访问初始化
修改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 动静分离配置,这里采用直接引用的方式。最终目录: