Search code examples
springangularspring-mvcangular5angular4-router

How to enter angular4 pages from spring mvc


I have angular4 + spring mvc project here is my project hierarchy

enter image description here

my index.html content

<!DOCTYPE html><html lang="en"><head>
  <meta charset="utf-8">
  <title>MonitoringFront</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>


    <script type="text/javascript" src="runtime.js"></script><script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="styles.js"></script><script type="text/javascript" src="vendor.js"></script><script type="text/javascript" src="main.js"></script></body></html>

and my web Configuration class

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "ge.mvc"})
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
       public InternalResourceViewResolver resolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setViewClass(JstlView.class);
          resolver.setPrefix("/WEB-INF/monitoringFront");
          return resolver;
       }

}

and when I want to enter my pages for example login page which is my default page I am getting page not fount error when i am trying to enter http://localhost:8080/springMvcApp/ url . Did I do something wrong ?

my router urls from angular 4 app.module.ts file

const appRoutes:Routes = [
  {
    path: '',
    component: LoginComponent
  },
  {
    path: 'dashboard',
    component: DashboardComponent
  }
]

Solution

  • I considere that your problem is equals with this question, because you want to render only de angular application,

    How to serve .html files with Spring

    In my point of view you need to split the problems to have a better architecture in one side you need your front end using angular 5 and in the other side spring mvc to create rest services, and also you probably will need JWT for authentication.