java - Problems with rendering JSP in spring boot -
i have spring boot application want use jsp
here dependencies in pom.xml
<parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.4.0.m2</version> <relativepath/> <!-- lookup parent repository --> </parent> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency> <groupid>org.jsoup</groupid> <artifactid>jsoup</artifactid> <version>1.8.3</version> </dependency> <dependency> <groupid>javax.mail</groupid> <artifactid>mail</artifactid> <version>1.5.0-b01</version> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-jasper</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-mail</artifactid> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <scope>runtime</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> </dependencies>
when try load jsp page has
<!doctype html>
then page partially shown correctly, not - example
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contenttype="text/html;charset=utf-8" language="java" pageencoding="utf-8"%> <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
is displayed on screen.
when delete <!doctype html>
- see plain html, no view.
i tried add , delete dependencies , if add or delete
<dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-jasper</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>org.apache.tomcat.embed</groupid> <artifactid>tomcat-embed-el</artifactid> <scope>provided</scope> </dependency>
nothing changes - still receive either plain html or partially visible jsp.
i have same problem both when run in intellijidea , when run compiled jar
i stuck here , feels won't ever make :( looked @ huge amount of tutorials , many questions on stackoverflow found no help.
any advice appreciated!
update when use pom.xml https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-web-jsp/pom.xml error
org.springframework.beans.factory.beandefinitionstoreexception: failed parse configuration class [name.valch.seasonvarapplication]; nested exception java.lang.illegalstateexception: failed introspect annotated methods on class org.springframework.boot.context.web.springbootservletinitializer @ org.springframework.context.annotation.configurationclassparser.parse(configurationclassparser.java:182) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclasspostprocessor.processconfigbeandefinitions(configurationclasspostprocessor.java:321) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclasspostprocessor.postprocessbeandefinitionregistry(configurationclasspostprocessor.java:243) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.support.postprocessorregistrationdelegate.invokebeandefinitionregistrypostprocessors(postprocessorregistrationdelegate.java:273) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.support.postprocessorregistrationdelegate.invokebeanfactorypostprocessors(postprocessorregistrationdelegate.java:98) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.support.abstractapplicationcontext.invokebeanfactorypostprocessors(abstractapplicationcontext.java:678) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:520) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.boot.springapplication.refresh(springapplication.java:766) [spring-boot-1.3.3.release.jar:1.3.3.release] @ org.springframework.boot.springapplication.createandrefreshcontext(springapplication.java:361) [spring-boot-1.3.3.release.jar:1.3.3.release] @ org.springframework.boot.springapplication.run(springapplication.java:307) [spring-boot-1.3.3.release.jar:1.3.3.release] @ org.springframework.boot.springapplication.run(springapplication.java:1191) [spring-boot-1.3.3.release.jar:1.3.3.release] @ org.springframework.boot.springapplication.run(springapplication.java:1180) [spring-boot-1.3.3.release.jar:1.3.3.release] @ name.valch.seasonvarapplication.main(seasonvarapplication.java:23) [classes/:na] @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[na:1.8.0_65] @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[na:1.8.0_65] @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[na:1.8.0_65] @ java.lang.reflect.method.invoke(method.java:497) ~[na:1.8.0_65] @ com.intellij.rt.execution.application.appmain.main(appmain.java:144) [idea_rt.jar:na] caused by: java.lang.illegalstateexception: failed introspect annotated methods on class org.springframework.boot.context.web.springbootservletinitializer @ org.springframework.core.type.standardannotationmetadata.getannotatedmethods(standardannotationmetadata.java:163) ~[spring-core-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclassparser.doprocessconfigurationclass(configurationclassparser.java:292) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclassparser.processconfigurationclass(configurationclassparser.java:232) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclassparser.parse(configurationclassparser.java:199) ~[spring-context-4.2.5.release.jar:4.2.5.release] @ org.springframework.context.annotation.configurationclassparser.parse(configurationclassparser.java:168) ~[spring-context-4.2.5.release.jar:4.2.5.release] ... 17 common frames omitted caused by: java.lang.noclassdeffounderror: javax/servlet/servletcontext @ java.lang.class.getdeclaredmethods0(native method) ~[na:1.8.0_65] @ java.lang.class.privategetdeclaredmethods(class.java:2701) ~[na:1.8.0_65] @ java.lang.class.getdeclaredmethods(class.java:1975) ~[na:1.8.0_65] @ org.springframework.core.type.standardannotationmetadata.getannotatedmethods(standardannotationmetadata.java:152) ~[spring-core-4.2.5.release.jar:4.2.5.release] ... 21 common frames omitted caused by: java.lang.classnotfoundexception: javax.servlet.servletcontext @ java.net.urlclassloader.findclass(urlclassloader.java:381) ~[na:1.8.0_65] @ java.lang.classloader.loadclass(classloader.java:424) ~[na:1.8.0_65] @ sun.misc.launcher$appclassloader.loadclass(launcher.java:331) ~[na:1.8.0_65] @ java.lang.classloader.loadclass(classloader.java:357) ~[na:1.8.0_65] ... 25 common frames omitted
try add properties application.properties
(src/main/resources/
):
spring.mvc.view.prefix: /web-inf/jsp/ spring.mvc.view.suffix: .jsp
put jsps /web-inf/jsp/
in controller return example "index" should have index.jsp in folder /web-inf/jsp/
make sure configuration , @enablewebmvc present.
import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.web.servlet.viewresolver; import org.springframework.web.servlet.config.annotation.defaultservlethandlerconfigurer; import org.springframework.web.servlet.config.annotation.enablewebmvc; import org.springframework.web.servlet.config.annotation.webmvcconfigureradapter; import org.springframework.web.servlet.view.internalresourceviewresolver; @configuration @enablewebmvc public class mvcconfiguration extends webmvcconfigureradapter { @bean public viewresolver getviewresolver() { internalresourceviewresolver resolver = new internalresourceviewresolver(); resolver.setprefix("/web-inf/jsp/"); resolver.setsuffix(".jsp"); return resolver; } @override public void configuredefaultservlethandling( defaultservlethandlerconfigurer configurer) { configurer.enable(); } }
update remove scope provided these dependencies:
<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