Commit 77cd8dc3 by yong.huang

add feign调用

parent d3a30303
...@@ -9,6 +9,7 @@ import com.freemud.demo.dto.PageReq; ...@@ -9,6 +9,7 @@ import com.freemud.demo.dto.PageReq;
import com.freemud.demo.dto.PageData; import com.freemud.demo.dto.PageData;
import com.freemud.demo.model.TDictData; import com.freemud.demo.model.TDictData;
import com.freemud.demo.model.TDictType; import com.freemud.demo.model.TDictType;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-demo-parent</artifactId>
<groupId>com.freemud.demo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feign-client</artifactId>
<dependencies>
<dependency>
<groupId>com.freemud.demo</groupId>
<artifactId>demo-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.freemud.controller;
import com.freemud.demo.dto.DictDataDto;
import com.freemud.demo.dto.ResDto;
import com.freemud.feign.IDictFeignService;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* @Auther: yong.huang
* @Date: 2018/11/20 10:07
* @Description:
*/
@RestController
@RequestMapping(value = "/dictFeign",produces = "application/json")
public class DictFeignController {
@Autowired
IDictFeignService dictFeignService;
@GetMapping(value = "/dictDatas/{dictTypeCd}")
public ResDto dictDatas(@PathVariable String dictTypeCd){
return this.dictFeignService.dictDatas(dictTypeCd);
}
@GetMapping(value = "/dictData/{dictTypeCd}/{dictCd}")
public ResDto<DictDataDto> dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){
return this.dictFeignService.dictData(dictTypeCd, dictCd);
}
}
package com.freemud.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
/**
* @Auther: yong.huang
* @Date: 2018/11/19 18:53
* @Description:
*/
@SpringBootApplication
@EnableFeignClients(basePackages = "com.freemud.feign")
@EnableEurekaClient
@ComponentScan(basePackages = "com.freemud")
public class FeignServerApplication {
public static void main(String[] args){
SpringApplication.run(FeignServerApplication.class, args);
}
}
package com.freemud.feign;
import com.freemud.demo.dto.DictDataDto;
import com.freemud.demo.dto.ResDto;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @Auther: yong.huang
* @Date: 2018/11/20 10:04
* @Description:
*/
@FeignClient(name = "dictionary", path = "/dict")
public interface IDictFeignService {
@GetMapping(value = "/dictDatas/{dictTypeCd}")
ResDto dictDatas(@RequestParam("dictTypeCd") String dictTypeCd);
@GetMapping(value = "/dictData/{dictTypeCd}/{dictCd}")
ResDto<DictDataDto> dictData(@RequestParam("dictTypeCd") String dictTypeCd , @RequestParam("dictCd") String dictCd);
}
spring:
application:
name: feign-client
server:
port: 9082
#log
logging:
config: classpath:logback.xml
swagger_enable: true
eureka:
instance:
statusPageUrlPath: ${management.context-path}/info
healthCheckUrlPath: ${management.context-path}/health
preferIpAddress: true
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--<springProperty scope="context"-->
<!--name="springAppName"-->
<!--source="spring.application.name"/>-->
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
</encoder>
</appender>
<appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" >
<layout class = "ch.qos.logback.classic.PatternLayout">
<!--<Pattern >%d{HH:mm} %-5level %logger{36} - [springAppName:${springAppName:-}, TxId : %X{X-B3-TraceId:-} , SpanId : %X{X-B3-SpanId:-}] %msg%n</Pattern >-->
<Pattern >%d{HH:mm} %-5level %logger{36} - [feign-client,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %msg%n</Pattern >
</layout >
</appender >
<root level="info">
<appender-ref ref="STDOUT_tid"/>
</root>
</configuration>
\ No newline at end of file
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<module>demo-service</module> <module>demo-service</module>
<module>eureka-server</module> <module>eureka-server</module>
<module>zuul-gateway</module> <module>zuul-gateway</module>
<module>feign-client</module>
</modules> </modules>
......
...@@ -33,7 +33,7 @@ public class DictController { ...@@ -33,7 +33,7 @@ public class DictController {
} }
@GetMapping("/dictData/{dictTypeCd}/{dictCd}") @GetMapping(value = "/dictData/{dictTypeCd}/{dictCd}")
public ResDto<DictDataDto> dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){ public ResDto<DictDataDto> dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){
DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true); DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true);
return new ResDto<>(dictDataDto); return new ResDto<>(dictDataDto);
......
...@@ -23,10 +23,14 @@ eureka: ...@@ -23,10 +23,14 @@ eureka:
zuul: zuul:
retryable: true #重试机制,默认重试3次 retryable: true #重试机制,默认重试3次
routes: routes:
api-system: api-dict:
path: /dict/** path: /dict/**
serviceId: dictionary serviceId: dictionary
stripPrefix: true stripPrefix: true
api-dictFeign:
path: /**
serviceId: feign-client
stripPrefix: true
host: host:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment