내 프로젝트에 이상한 문제가 있습니다. 필자는 Spring에서 서버 응용 프로그램을 작성하고 AngularJS로 프론트 엔드를 작성하기로 결정했습니다. 서버 측에서 간단한 엔티티에서 간단한 데이터를 반환하는 간단한 컨트롤러가 있습니다.). 그것은 다음과 같습니다 전면에Spring & AngularJS - RESTful API로 연결
@RestController
public class ApiController
{
@RequestMapping(value = "/getAllProfiles", method = RequestMethod.GET)
public Entity getEntity()
{
Entity e = new Entity();
e.setName("myname");
return e;
}
}
, 내가 보이는 Angulars 컨트롤러,이 같은 :
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");
});
})
및 HTML 파일 :
<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>
내가 서버를 시작, localhost : 8080/getAllProfiles에 연결하면 모든 것이 잘 작동합니다. 이 {"name":"myname"}
과 같은 JSON을받습니다. 그러나 Angular 측에서 동일한 작업을 시도하면 The content is
- 서버의 빈 데이터가 수신되고 물론 오류 기능이 컨트롤러에서 호출됩니다. CORS 문제 일 수 있다고 생각했지만 서버 쪽과 앵귤러쪽에 필터를 추가했는데 도움이되지 않았습니다. js 콘솔 (Chrome을 사용하고 있습니다) : 리소스를로드하지 못했습니다 : 서버가 404 상태 (응답 없음)로 응답 함
정말 어떻게해야할지 모르겠군요. 이 두 응용 프로그램 사이에서 "말하기"를 원하지만이 때문에이 작업을 수행 할 수 없습니다. 누군가가이 문제를 도와 줄 수 있다면 매우 감사 할 것입니다.
아마 차이는 없지만 http 구성에 GET 메소드 이름을 설정하는 것이 좋습니다.요청을 받으십시오. 분명히이 라인은 필요하지 않습니다. 이미 얻었습니다. – mindparse
예, 알고 있습니다. 이 http의 구조체 사이의 변경 사항은 문제를 해결하지 못합니다. – allocer
CORS가 문제가 아닌지 확인했다면 a) 스프링 애플리케이션이 8080에서 청취하고 b) 바인드 된 기본 경로가 없음 (즉, 일부/foo/getAllProfiles) ? – h7r