feign不使用eureka

main

@EnableFeignClients
@SpringBootApplication
public class FeignMain {
    public static void main(String[] args) {
        SpringApplication.run(FeignMain.class, args);
    }
}

server端代码

server端依旧是用randomInt

@RequestMapping(value = "/getNum", method = RequestMethod.GET)
    public int getRandomInt() {
        Random random = new Random();
        Integer num = random.nextInt(100);
        logger.info("getRandomInt:" + num);
        return num;
    }

Client端代码

@FeignClient(name = "thisOnlyName", url = "http://localhost:10102")
public interface RestFulService {
    /**
     * 默认没有参数会使用get方法
     *
     * @return
     */
    @RequestMapping(value = "/getNum")
    int getRandomInt();
}

此处通过url直接指定就好了。不需要配置eureka。ribbon也不会生效。单节点个人学习棒棒哒!

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐