私は春のブート(とサーブレット3.0)を初めて使用しています。私は、ビューとしてJSPを使用してspring mvcプロジェクトを作成しようとしています。私のコントローラからビューを返すと、JstlViewとして解決されません。ここでJSP用にspring boot mvc appを設定するには?
は私がやったことです:
src\main\webapp\WEB-INF\jsp
に両方の.jspファイルを作成し
@SpringBootApplication
public class MyApp extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);
}
}
@Controller
public class MainController {
@RequestMapping(value="/main" , method = RequestMethod.GET )
public String main(){
return "main";
}
@RequestMapping(value="/" , method = RequestMethod.GET )
public String welcome(){
return "welcome";
}
}
。
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
logging.level.org.springframework: TRACE
logging.level.com: TRACE
それが働いていなくても、この後:
はグーグル後、私はだから私は小道具に以下を追加私はapplication.propertiesでこれを指定する必要があることがわかりました。ここにトレースがあります。
2016-04-24 19:54:49.016 TRACE 7880 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Invoking [MainController.welcome] method with arguments []
2016-04-24 19:54:49.016 TRACE 7880 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Method [welcome] returned [welcome]
2016-04-24 19:54:49.020 DEBUG 7880 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2016-04-24 19:54:49.020 DEBUG 7880 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'welcome'
2016-04-24 19:54:49.022 DEBUG 7880 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory : Invoking afterPropertiesSet() on bean with name 'welcome'
2016-04-24 19:54:49.022 TRACE 7880 --- [nio-8080-exec-1] o.s.w.s.v.InternalResourceViewResolver : Cached view [welcome]
2016-04-24 19:54:49.022 DEBUG 7880 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'welcome'; URL [/WEB-INF/jsp/welcome.jsp]] based on requested media type 'text/html'
2016-04-24 19:54:49.022 DEBUG 7880 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'welcome'; URL [/WEB-INF/jsp/welcome.jsp]] in DispatcherServlet with name 'dispatcherServlet'
2016-04-24 19:54:49.022 TRACE 7880 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Rendering view with name 'welcome' with model {} and static attributes {}
2016-04-24 19:54:49.026 DEBUG 7880 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView : Forwarding to resource [/WEB-INF/jsp/welcome.jsp] in InternalResourceView 'welcome'
2
あなたがトレースで見たように、これはInternalResourceViewの代わりJstlViewとして/jsp/welcome.jsp解決しようとしています。最終的には404として失敗します。
私が従う必要があるその他の手順は? jspでSpringBoot-mvcのチュートリアルはありますか?
P.S. web.xml(JstlViewを自分の設定ファイルで使用)を使用してjspでspring mvc appを作成できます。しかし、jspを使ってSpringブートmvcのチュートリアルを見つけることはできません。あなたのpom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
であなたは以下のことを持っている必要があり、それはTomcatの、
埋め込まれていると仮定すると、
は、[この中に見てSO post](http://stackoverflow.com/questions/29953245/configure-viewresolver-with-spring-boot-and-annotations-gives-no-mapping-found-f)を参照してください。役立つかもしれません。ビューを解決するためには、 'InternalResourceViewResolver' Beanが必要です。 Spring Boot Applicationに相当するものが必要です。 –
Spring Bootには[JSPサンプルアプリケーション](https://github.com/spring-projects/spring-boot/tree/v1.3.3.RELEASE/spring-boot-samples/spring-boot-sample-web-jsp)があります。 ) –
公式のアプリケーションビルダーhttp://start.spring.ioを使用してアプリケーションを構成してください(デフォルトでは、JSPテンプレートエンジンを使用しています)。 –