澄清一下,这个问题只发生在 M1 Mac 上,intel 版本似乎没有这个问题。
JDK 17
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
# List of all JDK
Matching Java Virtual Machines (2):
17.0.1 (arm64) "Homebrew" - "OpenJDK 17.0.1" /opt/homebrew/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home
16.0.2 (arm64) "Azul Systems, Inc." - "Zulu 16.32.15" /Users/xxxxxx/Library/Java/JavaVirtualMachines/azul-16.0.2/Contents/Home
/opt/homebrew/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home
Run Code Online (Sandbox Code Playgroud)
项目图
问题:
java.lang.UnsatisfiedLinkError尝试通过 API-Gateway 访问某一微服务时会引发异常。比如http://localhost:8082/API-USER/users/status/ok会抛出这个异常。
该return值是正确的,尽管出现烦人的异常,API-Gateway 仍继续运行。
Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.ensureAvailability(MacOSDnsServerAddressStreamProvider.java:110) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
Caused …Run Code Online (Sandbox Code Playgroud) 当我测试我的代码时,我不小心遇到了意想不到的突变......或者......我只是做错了......
用户
constructor(
public id: number,
public education: Education[]
){}
Run Code Online (Sandbox Code Playgroud)
用户状态服务
private user = new BehaviorSubject<User>(null);
setUser(user:User){
// set by HttpClient or perform an update
this.user.next(user);
}
getUserDetail(){
return this.user.value;
// this.user.getValue(); => tried this as well same thing...
}
updateUserDetail(user:User){
// Maybe perform some check method before the update
this.user.next(user);
// HttpClient to save on db
}
Run Code Online (Sandbox Code Playgroud)
我的组件中有一个表单,用户将修改他们自己的数据。所以我这里的想法是调用getUserDetail()认为返回对象应该是只读的。一旦我设置了新值,我就会updateUserDetail()用 更新可观察对象next(),但我经历过其他情况......
成分
onSubmit(){
let currentUser = this.userService.getUserDetail();
console.log("Original User => ", currentUser); // array(2) see …Run Code Online (Sandbox Code Playgroud) 我只期待一个 http 请求,但在我的控制台中,我收到了多个 http 调用。我不完全确定原因。为了便于阅读,下面是一个缩写。
组件.html
{{ (user | async).firstname }} {{ (user | async).firstname }}
<ul>
<li *ngFor="let profile of (user | async)?.profiles ">
<div>
<p>{{ profile.profileType }}<span *ngIf="isStudent(profile.specialized)"> - {{ profile.specialized }}</span></p>
<p>{{ profile.id }}</p>
</div>
<button class="btn btn-primary float-right" (click)="onGo(profile)">Go</button>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
组件.ts
private user: Observable<User>;
ngOnInit(){
this.user = this.userDataService.fetchUserDetails(+params['id']);
}
Run Code Online (Sandbox Code Playgroud)
用户数据服务.ts
fetchUserDetails(id:number):Observable<User> {
console.log("calls 1 ?"); // this only gets called once!!!
return this.httpClient.get<User>(this.apiUrl + "/" + id)
.pipe(
tap((response) => {
console.log(response); // this is …Run Code Online (Sandbox Code Playgroud) 我不明白...我实际上定义了构造函数,但是
No constructor with 0 arguments defined in class
@Component
public class CustomMessageSource extends ReloadableResourceBundleMessageSource {
public CustomMessageSource(Locale locale){
this.propertiesHolder = getMergedProperties(locale);
this.properties = propertiesHolder.getProperties();
}
//... other setting, getters
Run Code Online (Sandbox Code Playgroud)
这就是我实例化的方式
CustomMessageSource customMessage = new CustomMessageSource(locale);
这是我的堆栈跟踪
Caused by: java.lang.NoSuchMethodException: com.app.service.CustomMessageSource.<init>()
at java.lang.Class.getConstructor0(Class.java:3074)
at java.lang.Class.getDeclaredConstructor(Class.java:2170)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
... 38 more
Run Code Online (Sandbox Code Playgroud) 我已经检查了这个https://github.com/angular/angular/issues/12129 但我没有看到任何解决方案......
Angular 2.0.1 AsyncPipe 不适用于 Rx Subject。
这里的解决方法是在组件中创建一个可观察的变量
我有但仍然没有工作......不知道为什么它不起作用,如果我将我的主题切换UserStateService到 BehaviorSubject 一切正常......
注意:UserDataService 和 UsersStateService 都在根 app.module.ts 中提供。
user-data.service.ts -> 发出我在组件中调用的 http 请求
fetchUsers():void{
this.httpClient.get<User[]>(this.apiUrl, {
observe: 'body',
responseType: 'json'
})
.subscribe( (response: User[])=>{
this.usersStateService.setUsersList(response); <-- set to local state service
});
}
Run Code Online (Sandbox Code Playgroud)
用户状态.service.ts
userListState = new Subject<User[]>(); <-- Change this to BehaviorSubject<User[]>([]) everything works!
setUsersList(users: User[]):void {
this.userListState.next(users.slice());
}
getUsersListState():Observable<User[]>{
return this.userListState.asObservable();
}
Run Code Online (Sandbox Code Playgroud)
组件.ts
users: Observable<User[]>;
ngOnInit() {
if(this.usersStateService.hasUserList()){
this.users = this.usersStateService.getUsersListState(); -|
|
// …Run Code Online (Sandbox Code Playgroud)