1. 程式人生 > 其它 >11.認證服務-初始化

11.認證服務-初始化

一、建立認證模組

1.1 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>

1.2 application.yaml

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

1.3 主啟動類

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);
    }
}

1.4啟動驗證

啟動服務,發現服務註冊進 Nacos

二、頁面及域名訪問初始化

2.1 修改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

2.2 配置閘道器轉發域名

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

2.3 引入登入頁面

將資料高階篇登入頁面和註冊頁面放到 templates 下,靜態檔案可以選擇 Nginx 動靜分離配置,這裡採用直接引用的方式。最終目錄: