I have a strange problem with my project. I decided to write the server application in Spring and a frontend with AngularJS. On the server side, I have a simple controller which return some simple data, from simple Entity ;). It looks like this:
@RestController
public class ApiController
{
@RequestMapping( value = "/getAllProfiles", method = RequestMethod.GET)
public Entity getEntity()
{
Entity e = new Entity();
e.setName( "myname" );
return e;
}
}
On the front side, I have an Angulars controller, which looks like:
var app = angular.module('app', []);
app.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
app.controller('Hello', function ($scope, $http) {
$http.get({
method: 'GET',
url: 'http://localhost:8080/getAllProfiles'
}).success(function (data) {
console.log('success', data)
$scope.greeting = data;
}).error(function(){
console.log("something goes wrong");
});
})
and html file:
<html ng-app="app">
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script>
<script src="view1.js"></script>
</head>
<body>
<div ng-controller="Hello">
<p>The content is {{greeting.name}}</p>
</div>
</body>
</html>
When I start server, I connect to the localhost:8080/getAllProfiles and everything works well. I receive JSON like this {"name":"myname"}
. But, when I try to do the same from the Angular side, I receive The content is
- an empty data from server and, of course, error function is calling in the controller. I thought it can be a CORS problem, but I added filters on server side, and on the Angular side and it didn't help.
The js console (I'm using Chrome) says: Failed to load resource: the server responded with a status of 404 (Not Found)
I really don't know what to do with this. I want "to talk" between this two applications, but I cannot because of this. If someone can help me with this, I will be very thankful.