1.
我正在使用Spring Boot。我的主類很簡單Spring引導中的@EnableWebMVC META-INF /資源無法正常工作
@ComponentScan
@EnableAutoConfiguration
@Configuration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
#2。現在我想將我的靜態內容外化爲一個jar文件。所以,下面是JAR項目
/pom.xml
/src/main/resources/META-INF/resources/hello.json // here is my resource
我做maven install
,把依賴到主應用程序,正常運行的應用程序。現在我可以調用http://localhost:8080/hello.json
來獲取我的hello.json文件
#3。然後,下一步是使用Apache瓷磚我主要的web項目,所以我創建了一個@EnableWebMvc
類配置tilesViewResolver
@Configuration
@EnableWebMvc
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
public @Bean TilesViewResolver tilesViewResolver() {
return new TilesViewResolver();
}
public @Bean TilesConfigurer tilesConfigurer() {
TilesConfigurer ret = new TilesConfigurer();
ret.setDefinitions(new String[] { "classpath:tiles.xml" });
return ret;
}
}
然後,我又開始應用,並嘗試hello.json
,以確保一切仍在正常工作。但是,404頁面出現。刪除WebMvcConfiguration
退回我的hello.json
。
我應該怎麼做才能解決這個問題?
非常感謝。
正確的,我想。只需刪除'@ EnableWebMvc'即可重新啓動引導功能。 旁白:JSP支持在一分鐘相當差,所以瓷磚可能是一個非首發。考慮使用Thymeleaf,或等待JSP趕上。 –
我有同樣的問題。從看代碼,默認位置是 「類路徑:/ META-INF /資源/」, 「類路徑:/資源/」, 「類路徑:/靜態/」, 「類路徑:/公/」。我在src/main/resources/static/image.jpg中放置了一個圖像,構建並運行了我的項目,並能夠在localhost上訪問該圖像:8080/image.jpg – Jay