title: Spring & AngularJS - connection with RESTful API
body: <p>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:</p>
  
  <pre><code>@RestController
  public class ApiController
  {
      @RequestMapping( value = "/getAllProfiles", method = RequestMethod.GET)
      public Entity getEntity()
      {
          Entity e = new Entity();
          e.setName( "myname" );
          return e;
      }
  }
  </code></pre>
  
  <p>On the front side, I have an Angulars controller, which looks like:</p>
  
  <pre><code>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");
      });
  })
  </code></pre>
  
  <p>and html file:</p>
  
  <pre><code>&lt;html ng-app="app"&gt;
  &lt;head&gt;
      &lt;title&gt;Hello AngularJS&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"&gt;&lt;/script&gt;
      &lt;script src="view1.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div ng-controller="Hello"&gt;
      &lt;p&gt;The content is {{greeting.name}}&lt;/p&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I start server, I connect to the localhost:8080/getAllProfiles and everything works well. I receive JSON like this <code>{"name":"myname"}</code>. But, when I try to do the same from the Angular side, I receive <code>The content is</code> - 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)</p>
  
  <p>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.</p>