-
spring boot + angular 2+ 404 not foundJAVA/Spring 2018. 1. 29. 22:58
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.resource.PathResourceResolver;
import java.io.IOException;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**/*")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location)
throws IOException {
Resource requestedResource = location.createRelative(resourcePath);
return requestedResource.exists() && requestedResource.isReadable()
? requestedResource
: new ClassPathResource("/static/index.html");
}
});
}
}spring boot 로 angular production mode 를 배포했을 때 /to/path 경로로 갔다 리로드를 하면 404 not found 가 뜬다
그럴때 처리방법
node.js 로 하면 angular universal 모듈로 처리하면 된다.. ( 훨씬 간단하지만 프로젝트가 나눠져서 보기 힘듬 )
from 스택오버플로우
'JAVA > Spring' 카테고리의 다른 글
spring boot + JPA + security 로그인 설정 (9) 2018.02.19 AWS 8080 포트 열기 (0) 2018.02.12 JAVA/Spring + Angular 5 POST 전송시 400 에러 (0) 2018.02.05 [spring boot 설정] 2017-10-03 버전 (0) 2017.10.03 spring 개발환경 구성하기 (0) 2017.10.02