Artikelverzeichnis der Serie
Erstellen Sie das SpringCloud-Alibaba-Projekt (1. Erstellen Sie das übergeordnete Projekt, die öffentliche Bibliothek und das Gateway).
Erstellen Sie das SpringCloud-Alibaba-Projekt (2. Erstellen Sie das Microservice-Authentifizierungs-Unterprojekt „store-authority-service“).
Erstellen Sie das SpringCloud-Alibaba-Projekt (3. Erstellen Sie das Service-Partei-Unterprojekt „store-user-service“).
Artikelverzeichnis
- Artikelverzeichnis der Serie
- Vorwort
- 1. Microservice-Unterprojekt Store-User-Service
- Zusammenfassen
Vorwort
Erstellen Sie das Service-Unterprojekt Store-User-Service, integrieren Sie mybatis-plus und nacos-discovery und stellen Sie die Funktion zum Hinzufügen, Löschen, Ändern und Überprüfen von Verbraucherbenutzern bereit.
1. Microservice-Unterprojekt Store-User-Service
1.1. Erstellen Sie ein Unterprojekt „Store-User-Service“.
Modul erstellen, Store-User-Service
1.2. Ändern Sie die pom.xml-Konfiguration
Abhängigkeiten hinzufügen: SpringWeb, Mybatis-Plus, Nacos-Discovery, öffentliche Bibliotheken usw.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>com.kelvin</groupId>
<artifactId>store-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<!--导入数据驱动-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
<version>8.0.33</version>
</dependency>
1.3. Ändern Sie die application.yml-Konfiguration
server:
port: 7776
spring:
application:
name: store-user-service
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos server 的地址
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/spring
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志
1.4. Plus-Paging konfigurieren
1.4.1, Abhängigkeiten hinzufügen
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
1.4.2, Konfiguration hinzufügen
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/***
* @title MybatisPlusConfig
* @desctption <TODO description class purpose>
* @author Administrator
* @create 2023/6/21 18:06
**/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return mybatisPlusInterceptor;
}
}
1.5. Konfigurieren Sie Nacos als Dienstanbieter
1.5.1, pom.xml konfigurieren
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
1.5.2, application.yml konfigurieren
spring:
application:
name: app-provider-service #服务名
cloud:
nacos:
discovery:
server-addr: localhost:8848
1.5.3. Konfigurieren Sie die Startup-Klasse und aktivieren Sie die Nacos-Erkennung
@EnableDiscoveryClient
Starten Sie die Anwendung und sehen Sie sich den Nacos-Hintergrund an
Zusammenfassen
Das Obige ist das, worüber ich heute sprechen möchte. In diesem Artikel wird kurz die Verwendung des Store-User-Service vorgestellt und [Benutzer können nach ID abfragen, Seiten abfragen, Schnittstellen hinzufügen, löschen und ändern] extern bereitgestellt werden, und es werden Microservice-Funktionen für Verbraucherbenutzer in verteilten Systemen bereitgestellt.