SpringCloud之Feign传递Json参数(我的使用)
java
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class FeignClientApplication {
public static void main(String[] args) {
SpringApplication.run(FeignClientApplication.class, args);
}
}spring
@RestController
@RequestMapping("/HelloController")
public class HelloController {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private HelloService helloService;
@RequestMapping(value = "/hello1", method = RequestMethod.GET)
public String hello1(@RequestHeader("username") String username, @RequestHeader("phone") String phone) {
HelloPojo helloPojo = new HelloPojo();
helloPojo.setUsername(username);
helloPojo.setPhone(phone);
String json = JSONObject.toJSONString(helloPojo);
return helloService.select1(json);
}
}app
@FeignClient(value = "SpringCloud-Feign-Server")
@RequestMapping("/HelloController")
public interface HelloService {
@RequestMapping(value = "/hello/select1", method = RequestMethod.POST,consumes = "application/json")
String select1(@RequestParam("json") String json);
}ide
pojo:spring-boot
public class HelloPojo implements Serializable {
private String username;
private String phone;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}ui
spring:
application:
name: SpringCloud-Feign-Client
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
instance:
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
server:
port: 9090
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-eureka
1.4.5.RELEASE
org.springframework.cloud
spring-cloud-starter-feign
1.4.5.RELEASE
com.alibaba
fastjson
1.2.4
org.springframework.cloud
spring-cloud-dependencies
Dalston.RC1
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
@SpringBootApplication
@EnableDiscoveryClient
public class FeignServerApplication {
public static void main(String[] args) {
SpringApplication.run(FeignServerApplication.class, args);
}
}
@RestController
public class HelloController implements HelloService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public String select1(String json) {
logger.info("SpringCloud-Feign-Server》》》》method--->select1:" + json);
return "SpringCloud-Feign-Server》》》》method--->select1:" + json;
}
}
@RequestMapping("/HelloController")
public interface HelloService {
@RequestMapping(value = "/hello/select1", method = RequestMethod.POST,consumes = "application/json")
String select1(@RequestParam("json") String json);
}
public class HelloPojo implements Serializable {
private String username;
private String phone;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
server:
port: 9051
spring:
application:
name: SpringCloud-Feign-Server
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
instance:
instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-feign
org.springframework.cloud
spring-cloud-dependencies
Dalston.RC1
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false