我的网关(gw-app)应用程序中有一个联系人实体,我想在每次在 UAA 应用程序中注册新用户时创建一个条目。我一直在尝试将Jhipster 文档中描述的服务间通信用于微服务。
- 我在这里遇到的第一个问题是我在 UAA 应用程序中没有这个界面
@AuthorizedFeignClient
。 - 其次,我从来没有成功地从 uaa 到 gw-app 使用
@FeignClient
.
除了与 feign 客户端的通信/配置问题之外,我还担心在没有会话建立(新用户注册)时这将如何工作,然后我有另一个用例,其中我有来自用户管理屏幕的现有会话(当管理员创建新用户时)
UAA 配置
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.uaa.auth",
"nativeLanguage": "es"
},
"jhipsterVersion": "4.13.3",
"baseName": "UAA",
"packageName": "com.agriket.auth",
"packageFolder": "com/uaa/auth",
"serverPort": "9999",
"authenticationType": "uaa",
"cacheProvider": "hazelcast",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": false,
"serviceDiscoveryType": "eureka",
"buildTool": "gradle",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"jwtSecretKey": "8e4167f67e9f8d85cc35b70181a828c691374e58",
"enableTranslation": true,
"applicationType": "uaa",
"testFrameworks": [],
"jhiPrefix": "jhi",
"nativeLanguage": "es",
"languages": [
"es",
"en"
],
"clientPackageManager": "yarn",
"skipClient": true
}
}
网关应用配置
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.app.gw",
"nativeLanguage": "es"
},
"jhipsterVersion": "4.13.3",
"baseName": "gwApp",
"packageName": "com.agriket.chat",
"packageFolder": "com/app/gw",
"serverPort": "9085",
"authenticationType": "uaa",
"uaaBaseName": "UAA",
"cacheProvider": "hazelcast",
"enableHibernateCache": true,
"websocket": "spring-websocket",
"databaseType": "sql",
"devDatabaseType": "mysql",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": false,
"serviceDiscoveryType": "eureka",
"buildTool": "gradle",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"clientFramework": "angularX",
"useSass": false,
"clientPackageManager": "yarn",
"applicationType": "gateway",
"testFrameworks": [],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "es",
"languages": [
"es",
"en"
]
}
}
客户代码
package com.uaa.auth.service.restClient;
import com.uaa.auth.service.restClient.Contact;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "gwApp")
@RequestMapping("/api")
public interface ContactClient {
@PostMapping("/contacts")
Contact createContact(@RequestBody Contact contact);
@GetMapping("/contacts/{id}")
Contact getContact(@PathVariable(name = "id") Long id);
}
接触
public class Contact {
private Long id;
private String login;
private String firstName;
private String lastName;
public Contact(User user) {
this.id = user.getId();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
}
public Long getId() {
return id;
}
public String getLogin() {
return login;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}