feign 改为 dubbo
This commit is contained in:
parent
30b9cef27f
commit
009cd44653
|
|
@ -1,10 +1,10 @@
|
|||
package com.czg;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
|
|
@ -12,9 +12,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.czg.service.account.mapper")
|
||||
@EnableDubbo
|
||||
public class AccountApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AccountApplication.class, args);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.service.account.feign.FeignSystemService;
|
||||
import com.czg.service.RedisService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -14,18 +14,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/feign")
|
||||
public class FeignController {
|
||||
|
||||
@Resource
|
||||
private FeignSystemService feignSystemService;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
@RequestMapping("/test")
|
||||
public String test() {
|
||||
String string = feignSystemService.testCall("sssss");
|
||||
System.out.println(string);
|
||||
redisService.set("sssss", string);
|
||||
return "test";
|
||||
SysParamsDTO test = sysParamsService.getParamsByCode2("test");
|
||||
return JSONObject.toJSONString(test);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,19 @@ spring:
|
|||
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
bootstrap:
|
||||
enabled: true
|
||||
data-id: system-server
|
||||
group: DEFAULT_GROUP
|
||||
auto-refresh: true
|
||||
server-addr: 101.37.12.135:8848
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
file-extension: yaml
|
||||
discovery:
|
||||
server-addr: 101.37.12.135:8848
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
|
||||
|
||||
dubbo:
|
||||
application:
|
||||
name: account-server
|
||||
qos-port: 22221
|
||||
qos-enable: true
|
||||
registry:
|
||||
address: nacos://101.37.12.135:8848 # Nacos 服务地址
|
||||
group: server
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9101
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,20 @@
|
|||
package com.czg;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableTransactionManagement
|
||||
@MapperScan("com.czg.service.system.mapper")
|
||||
@EnableDubbo
|
||||
public class SystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.SysParamsDTO2;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -12,8 +17,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/admin/feign")
|
||||
public class FeignController {
|
||||
|
||||
@Resource
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
@RequestMapping("/testCall/{name}")
|
||||
public String testCall(@PathVariable String name) {
|
||||
return "system-server:" + name;
|
||||
public CzgResult<SysParamsDTO2> testCall(@PathVariable String name) {
|
||||
return CzgResult.success(new SysParamsDTO2().setParamCode("system-server:" + name));
|
||||
}
|
||||
|
||||
@GetMapping("/sysParam/code/{code}")
|
||||
public SysParamsDTO getParamsByCode(@PathVariable String code) {
|
||||
CzgResult<SysParamsDTO> paramsByCode = sysParamsService.getParamsByCode(code);
|
||||
return paramsByCode.getData();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.system.dto.SysParamsDTO;
|
||||
import com.czg.service.system.service.SysParamsService;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
|
|||
|
|
@ -24,3 +24,15 @@ spring:
|
|||
discovery:
|
||||
server-addr: 101.37.12.135:8848
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
|
||||
dubbo:
|
||||
application:
|
||||
name: system-server
|
||||
qos-port: 22224
|
||||
qos-enable: true
|
||||
registry:
|
||||
address: nacos://101.37.12.135:8848 # Nacos 服务地址
|
||||
group: server
|
||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||
protocol:
|
||||
port: 9401
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cash-common-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>global-service</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-tools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.czg.service.system.dto;
|
||||
package com.czg.system.dto;
|
||||
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
|
|
@ -8,12 +8,14 @@ import jakarta.validation.constraints.NotNull;
|
|||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SysParamsDTO {
|
||||
public class SysParamsDTO implements Serializable {
|
||||
|
||||
@NotBlank(message = "参数编码不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
private String paramCode;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.czg.service.system.entity;
|
||||
package com.czg.system.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.czg.service.system.service;
|
||||
package com.czg.system.service;
|
||||
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.system.dto.SysParamsDTO;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.entity.SysParams;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.service.system.entity.SysParams;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -42,6 +42,7 @@ public interface SysParamsService extends IService<SysParams> {
|
|||
* @return 参数
|
||||
*/
|
||||
CzgResult<SysParamsDTO> getParamsByCode(String code);
|
||||
SysParamsDTO getParamsByCode2(String code);
|
||||
|
||||
/**
|
||||
* 根据参数类型获取参数
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.czg;
|
||||
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SysParamsDTO2 {
|
||||
|
||||
@NotBlank(message = "参数编码不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
||||
private String paramCode;
|
||||
|
||||
@NotBlank(message = "参数值不能为空", groups = DefaultGroup.class)
|
||||
private String paramValue;
|
||||
|
||||
@NotNull(message = "参数类型不能为空", groups = {UpdateGroup.class, UpdateGroup.class})
|
||||
private Integer paramType;
|
||||
private String remark;
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
<module>cash-common-sa-token</module>
|
||||
<module>cash-common-redis</module>
|
||||
<module>cash-common-api-config</module>
|
||||
<module>cash-common-service</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@
|
|||
<cloud-starter-loadbalancer.version>4.2.0</cloud-starter-loadbalancer.version>
|
||||
<jedis.version>5.2.0</jedis.version>
|
||||
<spring-data-redis.version>3.4.2</spring-data-redis.version>
|
||||
<dubbo-spring.version>3.3.3</dubbo-spring.version>
|
||||
<dubbo-registry-nacos.version>3.3.3</dubbo-registry-nacos.version>
|
||||
<dubbo.version>3.3.3</dubbo.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
@ -109,6 +112,23 @@
|
|||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<!-- Dubbo Spring Boot Starter -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>${dubbo-spring.version}</version>
|
||||
</dependency>
|
||||
<!-- Nacos Discovery for Dubbo -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
<version>${dubbo-registry-nacos.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
|
|
@ -142,25 +162,6 @@
|
|||
<version>${cloud-starter-bootstrap.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--openfeign依赖-->
|
||||
<!--start-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>${cloud-starter-openfeign.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>commons-io</groupId>-->
|
||||
<!-- <artifactId>commons-io</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!--end-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
package com.czg.service.account.feign;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@FeignClient("system-server")
|
||||
public interface FeignSystemService {
|
||||
@GetMapping("/admin/feign/testCall/{name}") // 使用 get 方式,调用服务提供者的 /call/{name} 接口
|
||||
String testCall(@PathVariable(value = "name") String name);
|
||||
}
|
||||
|
|
@ -41,6 +41,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.czg</groupId>
|
||||
<artifactId>cash-common-sa-token</artifactId>
|
||||
|
|
@ -51,18 +57,6 @@
|
|||
<artifactId>tomcat-embed-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
<version>1.10.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-processor</artifactId>
|
||||
<version>1.10.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
|
|
@ -90,28 +84,25 @@
|
|||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--openfeign依赖-->
|
||||
<!--start-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<!--end-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.czg.service.system.mapper;
|
||||
|
||||
import com.czg.system.entity.SysParams;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.service.system.entity.SysParams;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ package com.czg.service.system.service.impl;
|
|||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.system.dto.SysParamsDTO;
|
||||
import com.czg.service.system.entity.SysParams;
|
||||
import com.czg.service.system.mapper.SysParamsMapper;
|
||||
import com.czg.service.system.service.SysParamsService;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.entity.SysParams;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -23,9 +23,9 @@ import java.util.List;
|
|||
* @author mac
|
||||
* @since 2025-02-07
|
||||
*/
|
||||
@Service
|
||||
@DubboService(interfaceClass = SysParamsService.class)
|
||||
@CacheConfig(cacheNames = "params")
|
||||
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams> implements SysParamsService{
|
||||
public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams> implements SysParamsService {
|
||||
|
||||
@Override
|
||||
public CzgResult<String> insertParams(SysParamsDTO paramsDTO) {
|
||||
|
|
@ -103,6 +103,17 @@ public class SysParamsServiceImpl extends ServiceImpl<SysParamsMapper, SysParams
|
|||
return CzgResult.success(sysParamsDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysParamsDTO getParamsByCode2(String code) {
|
||||
SysParams sysParams = getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
|
||||
|
||||
if (sysParams == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return BeanUtil.toBean(sysParams, SysParamsDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<List<SysParamsDTO>> getParamsByType(Integer type) {
|
||||
List<SysParams> sysParamsList = list(new QueryWrapper().eq(SysParams::getParamType, type));
|
||||
|
|
|
|||
Loading…
Reference in New Issue