在
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Dalston.RELEASE
**版本中
使用 fegin做 服务调用,发现当 服务提供这,提供服务时候,没有进入 fallback,
需要加,**
feign:
hystrix:
enabled: true
调通的代码如下
controller
@RestController
@RequestMapping(value = "/sys/user")
public class UserLoginController {
@Autowired
private UserLoginService userLoginService;
@Autowired
private JwtService jwtService;
@RequestMapping(value = "/login/{username}/{password}",method = RequestMethod.GET)
public ReturnDTO login(@PathVariable("username") String username, @PathVariable("password") String password) {
ReturnDTO returnDTO = new ReturnDTO();
Map<String, Object> message = new HashMap<String, Object>();
boolean isSuccess = userLoginService.login(username, password);
if (isSuccess) {
String token = jwtService.createJWT(username, 1);
returnDTO.setCode(true);
message.put("token", token);
returnDTO.setMessage(message);
} else {
returnDTO.setCode(false);
}
return returnDTO;
}
service
@FeignClient(value = "jwt-service")
public interface JwtService {
@RequestMapping(value = "/create",method = RequestMethod.GET)
String createJWT(@RequestParam(value = "username")String username, @RequestParam(value = "id")Integer id);
}
@FeignClient(value ="${userlogin.name}" ,fallback = UserLoginServiceHystrix.class)
public interface UserLoginService {
@RequestMapping(value = "${userlogin.url}",method = RequestMethod.GET)
Boolean login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password);
}
@Component
class UserLoginServiceHystrix implements UserLoginService {
@Override
public Boolean login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password) {
return false;
}
}
配置文件
server:
port: 9002
eureka:
client:
service-url:
defaultZone: http://10.10.8.101:9000/eureka/
spring:
application:
name: sys-user-consumer
messages:
fallback-to-system-locale: true
management:
security:
enabled: false
userlogin:
name: sys-user-service
url: /sys/user/login
feign:
hystrix:
enabled: true
博客小福利 阿里云优惠券 点我免费领取
我的官网
我的CSDN地址http://blog.csdn.net/chenjianandiyi
我的简书地址http://www.jianshu.com/u/9b5d1921ce34
我的githubhttps://github.com/javanan
我的码云地址https://gitee.com/jamen/