I Spring 4 mit Thymeleaf integrieren will, aber ich habeKeine Zuordnung gefunden für HTTP-Anforderung mit URI in DispatcherServlet, mit Thymeleaf und Spring 4
WARNING [http-apr-8080-exec-4] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/hire-platform/] in DispatcherServlet with name 'mvc-dispatcher'
und Inhalt von /WEB-INF/templates/index.html
wird nicht angezeigt. Hier ist 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>
Wo servletContext
Bohne ist voll von How to set ServletContext property for a bean in Spring XML metadata configuration answer kleistert kopieren, als Konstruktor Parameter benötigt wird, wie ich in meiner vorherigen Frage gefunden, Failed to instantiate [org.thymeleaf.templateresolver.ServletContextTemplateResolver]: No default constructor found. Ich denke, es sollte in HTML-Datei umleiten (index.html
), als ich JSP (index.jsp
) anstelle von Thymeleaf verwendet, funktionierte es. Vielleicht fehlt mir etwas in applicationContext.xml
Datei? Hier ist, wie applicationContext.xml
Datei aussieht:
<?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 Spring AOP
Teil entfernt, SessionFactory
Bohne und <!--<mvc:annotation-driven/>-->
Kommentar, weil ich denke, dass sie hier nicht gebraucht werden. Ich habe Thymeleaf Abhängigkeiten von Maven in pom.xml
enthalten:
<!-- 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>
Also, ich bin mir ziemlich sicher, dass ich etwas einfach, wie eine Konfigurationszeile am fehlt. Ich wäre dankbar, wenn mir jemand helfen würde, danke im Voraus. P.S. ich auch web.xml-Datei, weil ich sehe, ähnliche Fragen, die es haben:
<!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>
<!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext. It is registered to 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>
Ich habe auch versucht, einen Controller hinzufügen:
@Controller
public final class MainController {
@RequestMapping(value = "/")
public String displayFirstView() {
return "index.html";
}
}
Aber es half nicht. Lösung: Ich vermisste <mvc:annotation-driven/>
in applicationContext.xml
und ich muss einen Controller für die erste Ansicht haben (wie MainController
, die ich hier aufgenommen). Danke für die Benutzer, die mir bei diesem Problem sehr geholfen haben.
Suchen Sie im Serverprotokoll. mybe ein Problem in der Bereitstellung – Jens
@Jens Ich habe nur 'org.hsqldb.HsqlException: Benutzer fehlt Privileg oder Objekt nicht gefunden: PUBLIC.LANGUAGES_LIST' im Zusammenhang mit Hibernate in 'Tomcat Catalina' Registerkarte, aber wenn ich JSP ohne Thymeleaf verwendet, es auch aufgetreten, aber index.jsp wurde angezeigt –
Sieht so aus, als ob Sie Ihre Datenbank überprüfen müssen Access-Daten – Jens