jHipster - 微服务之间互相调用
2017-04-06 本文已影响355人
CC_简书
此方法不可用于 uaa和gateway。
其中 xxx 代表微服务的名称
@AuthorizedFeignClient(name = "xxx")
interface XxxClient {
// 此处需要注意 不可用 @GetMapping @PostMapping
@RequestMapping(value = "/api/some-entities/{id}")
SomeEntity getSomeEntityById(Long @Path("id") id);
}
and inject it in any spring service / rest-controller like this
@Resource
private XxxClient xxxClient;
//...
pubic void someAction() {
//...
xxxClient.getEntityById(id);
//..
}
还有一个地方需要配置的 application*.yml
## 其中有以下一段
jhipster:
http:
version: V_1_1 # To use HTTP/2 you will need SSL support (see above the "server.ssl" configuration)
cache: # Cache configuration
hazelcast: # Hazelcast distributed cache
time-to-live-seconds: 3600
backup-count: 1
security:
client-authorization:
access-token-uri: http://uaa/oauth/token
token-service-id: uaa
client-id: internal
client-secret: internal
jhipster.security.client-authorization.client-id 的配置无法被jhipster读取
## 通过源码发现 使用的是 security.client-authorization.client-id
@Configuration
@ConditionalOnClass({ ClientCredentialsResourceDetails.class, LoadBalancerClient.class })
@ConditionalOnProperty("security.client-authorization.client-id")
public class UaaAutoConfiguration {
.....
}
## 将配置文件security节点移动到jhipster外就可以了。(也许后面的版本会优化)
security:
client-authorization:
access-token-uri: http://uaa/oauth/token
token-service-id: uaa
client-id: internal
client-secret: internal