我在尝试将 RESTful API 从 Angular 发送到 EJB 时遇到了一些问题。这是我的 component.ts:
this.opUserAdminWinService.retrievePegRoleList().subscribe(resf => {
console.log(resf);
});
还有我的 service.ts:
serviceAPI = SERVER_API_URL;
mainAPI = '/api/securityactivity/securityactivity';
retrievePegRoleList() {
const url: string = this.serviceAPI + this.mainAPI + '/RetrievePegRoleList';
return this.http.post(url, this.httpOptions);
}
在我的 Controller.java 中:
@PostMapping("/RetrievePegRoleList")
public Vector RetrievePegRoleList()
throws JaMClientRemoteException, JaMException {
return getSecurityActivity().RetrievePegRoleList();
}
在我的 EjbBean 类中:
public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException;
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Vector RetrievePegRoleList() throws JaMClientRemoteException, JaMException
{
Vector pegRoleList;
try {
String dataSource = JaM.getProperties().ORD_DATA_SOURCE;
RetrievePegRoleListTask retrievePegRoleListTask = new RetrievePegRoleListTask(dataSource);
retrievePegRoleListTask.execute();
pegRoleList = retrievePegRoleListTask.getResult();
} catch (Exception e) {
throw new JaMClientRemoteException(this.ERR_EXCEPTION_JAM, e.toString());
}
return pegRoleList;
}
但是,我收到此错误消息:
有什么想法为什么会这样吗?谢谢!
最佳答案
尝试一下 Angular 。
export const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
this.http.post(your-url,your-data, httpOptions);
我总是以 Angular 发送这样的帖子。 如果不起作用。你应该检查一下Server中是否有拦截器。
关于java - Angular POST RESTful API 到 Ejb 导致 404 未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58262794/