Angular2 + Spring Boot 어플리케이션을 개발 중입니다. 현재로서는 다음과 같습니다.
백엔드 : @RequestMapping으로 주석 된 메소드가있는 @RestController.스프링 부트 @RequestMapping annotation
@RequestMapping("/main")
public Band[] main(@RequestParam(value="numberOfBands", required=false, defaultValue="3") int numberOfBands) throws ClientProtocolException, IOException {
return random(numberOfBands);
}
프런트 엔드 :]에 '/ 메인'초기화시
{ path: '', redirectTo: 'main', pathMatch: 'full' },
, 내 main.component.ts 스프링하는 요청을 전송하고 응답으로서 오브젝트의 배열을 얻을 리디렉션 app.routing.ts, 구성 요소는 다음과 같습니다 http://localhost:8090/
에 갈 때
export class MainComponent {
bands: Band[];
errorMessage: string;
constructor(private bandService: BandService){
//this.bands = new Array(3);
bandService.getRandomBands(3)
.subscribe(
bands => this.bands = bands,
error => this.errorMessage = <any>error);
}
}
앱을 /main
로 리디렉션 및 밴드가 제대로 전달 구성 요소에 의해 구문 분석됩니다. 하지만 언제든지 페이지를 다시로드하려고 시도 할 때마다 http://localhost:8090/main
일반 JSON 만 가져옵니다. 구성 요소가 올바르게 초기화되지 않은 것처럼 보입니다.
스프링 부트가 주소 표시 줄의 경로를 무시하므로 클라이언트 측에만 관련이 있습니다.
질문 : 서버 측에서 문제가 발생하거나 구성 요소를 부적절하게 초기화하는 것입니까?
UPDATE 내 모든 @RequestMappings에 접두사 "/ API"를 추가하고 ('동일'기능을 테스트하기 위해 단지이다) 다음과 같은 필터를 추가 한
:
if(requestURI.equals("/main")){
RequestDispatcher requestDispatcher = httpServletRequest.getRequestDispatcher("/");
requestDispatcher.forward(req, res);
}
chain.doFilter(req, res);
그 후, 전달 프로세스가 예상대로 진행되었습니다.
스프링 리턴을 뷰로 만들지 않으므로 결과적으로 클라이언트가 초기화되지 않습니까? –
필터가 index.html로 전달되면 말입니까? 당신이 묻고있는 것을 분명히 할 수 있습니까? –
답을 따르려고했지만 스프링 부트 앱이 요청을 index.html로 리디렉션 할 때 해당 값에 대한 requestMapping이 없습니다. 그래서 void를 반환하는 requestMapping 메서드를 추가했지만 반환 된 뷰가 null이므로 각도 응용 프로그램이 초기화되지 않았습니다. –