java - How to configure spring boot mvc app for JSP? -
i new spring boot ( , servlet 3.0 ). trying create spring mvc project jsp view. when return view controller not getting resolved jstlview.
here did:
@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"; } }
created both .jsp files in src\main\webapp\web-inf\jsp
.
after googling found need specify in application.properties added following in props:
spring.mvc.view.prefix: /web-inf/jsp/ spring.mvc.view.suffix: .jsp logging.level.org.springframework: trace logging.level.com: trace
even after not working. here trace.
2016-04-24 19:54:49.016 trace 7880 --- [nio-8080-exec-1] .w.s.m.m.a.servletinvocablehandlermethod : invoking [maincontroller.welcome] method 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 [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] based on accept header types , 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 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 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 name 'dispatcherservlet' 2016-04-24 19:54:49.022 trace 7880 --- [nio-8080-exec-1] o.s.w.servlet.view.internalresourceview : rendering view name 'welcome' model {} , static attributes {} 2016-04-24 19:54:49.026 debug 7880 --- [nio-8080-exec-1] o.s.w.servlet.view.internalresourceview : forwarding resource [/web-inf/jsp/welcome.jsp] in internalresourceview 'welcome' 2
as see in trace, trying resolve /jsp/welcome.jsp internalresourceview instead of jstlview. fails 404.
what other steps need follow? there tutorial springboot-mvc jsp ?
p.s. can create spring mvc app jsp using web.xml ( using jstlview in config file ). can't find tutorial spring boot mvc jsp.
@bean public viewresolver getviewresolver(){ internalresourceviewresolver resolver = new internalresourceviewresolver(); resolver.setprefix("/web-inf/jsp/"); resolver.setsuffix(".jsp"); resolver.setviewclass(jstlview.class); return resolver; }
also needed , pages should @ /webapp/web-inf/jsp/
+
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-tomcat</artifactid> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-jasper</artifactid> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> </dependency>
Comments
Post a Comment