启动类⬇
package com.tz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages= {"com.tz"})
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
feign接口⬇
package com.tz.services;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(name="compute-service")
public interface ITestFeign {
@RequestMapping(value = "feignTest", method = RequestMethod.GET)
public String testFeign();
}
feigin接口的实现类⬇
package com.tz.services.impl;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.tz.services.ITestFeign;
@Service
public class TestFeign implements ITestFeign {
@Override
public String testFeign() {
return "测试feign调用";
}
}
Controller⬇
package com.tz.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.tz.services.ITestFeign;
import com.tz.services.impl.TestFeign;
import com.tz.vos.TestVo;
import org.apache.log4j.Logger;
@RestController
public class ClientController {
private final Logger logger = Logger.getLogger(getClass());
@Autowired
private ITestFeign testFeign;
@RequestMapping(value = "feignTest", method = RequestMethod.GET)
//@ResponseBody
public String testFeign() {
logger.info("======testFeign========");
String str = testFeign.testFeign();
logger.info("======str========"+str);
return str;
}
}
spring.application.name=compute-service
server.port=2222
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
hystrix.command.default.execution.timeout.enabled=true
hystrix.threadpool.default.coreSize=500000
hystrix.command.default.circuitBreaker.requestVolumeThreshold=1000
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=300000
ribbon.ConnectTimeout=3000
ribbon.ReadTimeout=3000
eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
logging.level.root=debugger
调用之后就一直报超时,也不知道什么原因,请大神帮我看看,谢谢。