2017-02-10 118 views
0

我想我的資源的子文件映射到服務器的index.html和相關圖片的春天引導映像資源。子文件夾

我的資源位於文件夾資源/ A/B/C的內部。 (即資源/ A/B/C/index.html的)

我想這個HTML網頁從我的根路徑(http://localhost:8080/index.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"); 
    } 
} 

有人能給我一些指導嗎?

感謝

+0

嘗試添加重定向'@Override public void addViewControllers(ViewControllerRegistry registry){ registry.addRedirectViewController(「index.html」,「/a/b/c/index.html」); super.addViewControllers(registry); }' – azl

回答

1

documentation

默認春天啓動的任期將從一個名爲/靜態(或/公共或/資源或/ META-INF /資源)目錄 靜態內容 類路徑或從ServletContext的根。

所以,如果您有:

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

注意添加時,你不能添加在URL靜態的,必須重新啓動服務器:

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

您可以通過訪問你的資源新資源。