系列文章目录
构建SpringCloud alibaba项目(一、构建父工程、公共库、网关)
构建SpringCloud alibaba项目(二、构建微服务鉴权子工程store-authority-service)
构建SpringCloud alibaba项目(三、构建服务方子工程store-user-service)
前言
构建服务方子工程store-user-service,集成mybatis-plus、nacos-discovery,提供消费者用户类的增删改查功能。
1、微服务子工程store-user-service
1.1、创建子工程store-user-service
创建Module,store-user-service
1.2、修改pom.xml配置
加入依赖:springWeb、mybatis-plus、nacos-discovery、公共库等
<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、修改application.yml配置
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分页
1.4.1、添加依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
1.4.2、添加配置
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、配置nacos,作为服务提供者
1.5.1、配置pom.xml
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
1.5.2、配置application.yml
spring:
application:
name: app-provider-service #服务名
cloud:
nacos:
discovery:
server-addr: localhost:8848
1.5.3、配置启动类,开启Nacos discovery
@EnableDiscoveryClient
启动应用,查看nacos后台
文章来源:https://www.toymoban.com/news/detail-496412.html
总结
以上就是今天要讲的内容,本文简单介绍了store-user-service的使用,对外提供提供【用户根据ID查询、分页查询、增加、删除、修改接口】,为分布式系统提供消费端用户的微服务功能。文章来源地址https://www.toymoban.com/news/detail-496412.html
到了这里,关于《项目实战》构建SpringCloud alibaba项目(三、构建服务方子工程store-user-service)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!