cst1992 cst1992 - 6 months ago 22
AngularJS Question

AngularJS templates don't work with Spring

I have developed a REST application using Spring in NetBeans IDE.
Here is the relevant dir structure:
project structure

I want to integrate Angular functionality into it, but will prefer to keep it as a single app, rather than separate Angular and Spring apps.

The main

index.html
file should show the template
home.html
on the front page.

The Problem:

Adding HTML files to the
templates
folder doesn't seem to work in the Angular application. If I try to access the
index.html
and
home.html
files through Angular, I get a 404 error, but I can open them directly.

Here's the controller in my Spring application for these two files:

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

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


I have written AngularJS code before by itself, and I didn't have any problems.


  • Am I mixing some things that I shouldn't?

  • Do I create all my AngularJS code in a separate folder, away from
    src/main/resources
    ?


Answer

A crude way to do this was to place the main index.html file in the src/main/resources/templates directory, and place all other resources required by the Angular app in src/main/resources/static/. To avoid confusion with the outside templates folder, I named the folder with the Angular templates as views.

Comments