2017-02-10 4 views
0

내 리소스의 하위 폴더를 서버 index.html 및 이미지와 연결하려고합니다.하위 폴더의 Spring 부트 매핑 리소스

내 리소스는 폴더 리소스/a/b/c 내에 있습니다. (예 : resources/a/b/c/index.html)

루트 경로 (http://localhost:8080/index.html)에서이 html 페이지에 액세스 할 수있게하려고합니다.

WebMvcConfigurerAdapter를 확장하여 매핑을 구성합니다. 여러 경로를 시도했지만 지금까지 아무 것도 작동하지 않았습니다.

@SpringBootApplication 
public class Application extends WebMvcConfigurerAdapter 
{ 
    public static void main(String[] args) 
    { 
     SpringApplication.run(Application.class, args); 
    } 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) 
    { 
     registry.addResourceHandler("/**").addResourceLocations(
      "classpath:/resources/a/b/c", 
      "classpath:/a/b/c", 
      "/resources/a/b/c", 
      "https://stackoverflow.com/a/b/c", 
      "classpath:resources/a/b/c", 
      "classpath:a/b/c", 
      "resources/a/b/c", 
      "a/b/c"); 
    } 
} 

누군가 내게 이에 대한 지침을 줄 수 있습니까?

덕분에 documentation에서

+0

리디렉션 '@Override를 추가하십시오. public void addViewControllers (ViewControllerRegistry registry) { registry.addRedirectViewController ("index.html", "/a/b/c/index.html"); super.addViewController (레지스트리); }' – azl

답변

1

: 봄 부팅 (/ 자원을 공용 또는/자원이나/META-INF 또는 /)/정적라는 디렉토리 에서 정적 콘텐츠를 제공합니다 기본적으로

에서 클래스 경로 또는 ServletContext 루트에서.

, 당신은 그래서 경우에 다음을 추가 할 때 서버 URL에 정적 추가하지 않아야하고 다시 시작해야합니다

http://localhost:8080/ (index.html) 
http://localhost:8080/index.html 
http://localhost:8080/images/image.png 

주의 사항 :

src 
└── main 
    └── resources 
     └── static 
      ├── images 
      │    └── image.png 
      └── index.html 

당신은을 통해 리소스에 액세스 할 수 있습니다 새로운 자원.

관련 문제