Moatez Bouhdid Moatez Bouhdid - 5 months ago 16
AngularJS Question

AngularJs view with Spring : Not showing

So I have a simple application AngularJs and Spring mvc. I have a controlller that mapped to the angularJs page and I have this code in a jsp page :

<div ng-app="myApp" ng-controller="myCtrl">
<p>The name is <span ng-bind="person.lastName"></span></p>
{{ lastName }}

<script src="applications.js"></script>
<script src="controllers.js"></script>

application.js :

var app = angular.module("myApp", []);

controllers.js :

app.controller("myCtrl", function($scope) {
$scope.firstName = "John";
$scope.lastName= "Doe";

when I run this with Pivotal it dosn't run, but when I access the file directly within my browser it works like a charm, Someone care to explain pls ?

Thank you.

public class WebConfig extends WebMvcConfigurerAdapter {
public void addResourceHandlers(ResourceHandlerRegistry registry) {


public void configureDefaultServletHandling ( DefaultServletHandlerConfigurer configurer )

resources folder :

Resources folder

The URL : http://localhost:8080/gestionprojet/Project/angularjs

My Controller :

public String getAngularJs() {
return "AngularJs";


First of all, your files are under /WEB-INF/resources, but you have configured spring to load static resources from /resources. So they can't be served at all. The config should be


The URL of your page is


Your page tries to load the script using the relative path


So the corresponding absolute path where the browser looks for the JS files is


which doesn't match with the URLs you choose to serve static resources from. Assuming /gestionprojet is the context path of the application, the absolute URL should be


So the source code in the JSP should thus be

<script src="${pageContext.request.contextPath}/resources/applications.js"></script>