java - No mapping found for HTTP request with URI in DispatcherServlet, with Thymeleaf and Spring 4 -
i want integrate spring 4 thymeleaf, got
warning [http-apr-8080-exec-4] org.springframework.web.servlet.pagenotfound.nohandlerfound no mapping found http request uri [/hire-platform/] in dispatcherservlet name 'mvc-dispatcher'
and content of /web-inf/templates/index.html
not displayed. here mvc-dispatcher-servlet-xml
:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" > <bean id="viewresolver" class="org.thymeleaf.spring4.view.thymeleafviewresolver" p:templateengine-ref="templateengine" p:characterencoding="utf-8" > </bean> <bean id="servletcontext" class="beans.servletcontextfactory" ></bean> <bean id="templateresolver" class="org.thymeleaf.templateresolver.servletcontexttemplateresolver" p:prefix="/web-inf/templates/" p:suffix=".html" p:templatemode="html5" > <constructor-arg ref="servletcontext"/> </bean> <bean id="templateengine" class="org.thymeleaf.spring4.springtemplateengine" p:templateresolver-ref="templateresolver" > </bean>
where servletcontext
bean copy-pasted how set servletcontext property bean in spring xml metadata configuration answer, needed constructor parameter found in previous question, failed instantiate [org.thymeleaf.templateresolver.servletcontexttemplateresolver]: no default constructor found. think should redirect html file (index.html
), when used jsp (index.jsp
) instead of thymeleaf, worked. maybe missing in applicationcontext.xml
file? here how applicationcontext.xml
file looks:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "> <jdbc:embedded-database id="datasource" type="hsql"> </jdbc:embedded-database> <context:component-scan base-package="beans"/> <bean id="transactionmanager" class="org.springframework.orm.hibernate5.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory"></property> </bean> <tx:annotation-driven />
i removed spring aop
part, sessionfactory
bean , <!--<mvc:annotation-driven/>-->
comment because think not needed here. have thymeleaf dependencies maven included in pom.xml
:
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>4.0.0-b01</version> </dependency> <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf --> <dependency> <groupid>org.thymeleaf</groupid> <artifactid>thymeleaf</artifactid> <version>3.0.0.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 --> <dependency> <groupid>org.thymeleaf</groupid> <artifactid>thymeleaf-spring4</artifactid> <version>3.0.0.release</version> </dependency>
so, pretty sure missing simple, 1 configuration line. grateful if me, thank in advance. p.s. include web.xml file, because see similar questions have it:
<!doctype web-app public "-//sun microsystems, inc.//dtd web application 2.3//en" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>archetype created web application</display-name> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/applicationcontext.xml</param-value> </context-param> <!-- bootstrap listener start , shut down spring's root webapplicationcontext. registered servlet container --> <listener> <listener-class> org.springframework.web.context.contextloaderlistener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.requestcontextlistener </listener-class> </listener> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
i have tried add controller:
@controller public final class maincontroller { @requestmapping(value = "/") public string displayfirstview () { return "index.html"; } }
but did not help. solution: missed <mvc:annotation-driven/>
in applicationcontext.xml
, have have controller first view (like maincontroller
included here). users helped me lot problem.
you missing <mvc:annotation-driven/>
required read @controller
annotation. try add it.
Comments
Post a Comment