ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • spring boot + angular 2+ 404 not found
    JAVA/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 스택오버플로우

    댓글

Designed by Tistory.