[英]Spring boot and angular app, issue in deploying war file in tomcat container
我在 Spring boot 2.6.6 和 Angular 6.1.0 中有一个应用程序。 我试图在一场战争中部署这两个应用程序。 如果在 Eclipse 和 Angular 应用程序中分别作为 Spring Boot 应用程序运行,则应用程序在上下文路径中运行良好。 但是如果我在 tomcat (9.0.30) 中运行,应用程序不会加载。 对于 URL localhost:8080/Demo/#/login ,我在浏览器屏幕上获得了一些 JSON 内容。
{
"_links": {
"users": {
"href": "http://localhost:8080/Demo/index.html/users{?page,size,sort}",
"templated": true
},
"country": {
"href": "http://localhost:8080/Demo/index.html/country{?page,size,sort}",
"templated": true
}
...
...
...
}
}
我也尝试过 URL - localhost:8080/Demo/index.html,然后我可以看到应用程序 UI。 但是在刷新页面 URL 时,会更改为 localhost:8080/Demo/#/login 并在 UI 上显示相同的 JSON。
你必须在你的 spring 应用程序中添加一个控制器
@Controller
public class RouteToAngular implements ErrorController {
@RequestMapping("/error")
public String handleError() {
return "/";
}
public String getErrorPath() {
return "/error";
}
}
您的 Angular 中的 index.html 在头部添加<base href="/">
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>App title</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.