0

I have an application in Spring boot 2.6.6 and Angular 6.1.0. I am trying to deploy both apps in a single war. Application is running fine with context path if running as spring boot app in eclipse and Angular app separately. But if I run in tomcat (9.0.30) application is not loading. For URL localhost:8080/Demo/#/login , I am getting some JSON content on browser screen.

{
    "_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
        }
        ...
        ...
        ...
    }
}

I have also tried URL - localhost:8080/Demo/index.html, then I can see the application UI. But on refreshing the page URL getting changed to localhost:8080/Demo/#/login and getting same JSON displayed on UI.

  • What is the context root of your backend- Spring Boot app? – Supritam Jun 03 '22 at 07:23
  • Please take a look at this answer, [Deploy WAR file on Tomcat of Spring boot and Angular App](https://stackoverflow.com/questions/64331552/deploy-war-file-on-tomcat-of-spring-boot-and-angular-app) – Eskandar Abedini Jun 03 '22 at 07:31

1 Answers1

0

you must add a controller to your spring app

@Controller
public class RouteToAngular implements ErrorController {

@RequestMapping("/error")
public String handleError() {
    return "/";
}


public String getErrorPath() {
    return "/error";
}
}

your index.html in your Angular add <base href="/"> in the head

<!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>