2016-06-28 2 views
0
내가 Thymeleaf와 스프링 (4)을 통합하려는

으로의 DispatcherServlet에 URI와 HTTP 요청을 찾을 수 없습니다,하지만 난 에 매핑이 Thymeleaf 봄 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' 

을 가지고 그리고 /WEB-INF/templates/index.html의 내용이 표시되지 않습니다. 여기 mvc-dispatcher-servlet-xml입니다 : 내 이전 질문, Failed to instantiate [org.thymeleaf.templateresolver.ServletContextTemplateResolver]: No default constructor found에서 발견

servletContext 콩이 완전히 How to set ServletContext property for a bean in Spring XML metadata configuration answer부터 붙여 복사됩니다
<?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> 

은,이 생성자 매개 변수로 필요합니다. Thymeleaf 대신 JSP (index.jsp)를 사용하면 HTML 파일 (index.html)으로 리디렉션해야한다고 생각합니다. 어쩌면 applicationContext.xml 파일에 뭔가 빠졌습니까? 여기 applicationContext.xml 파일이 모습입니다 : 나는 그들이 여기에 필요하지 않은 생각하기 때문에 내가 Spring AOP 부분 SessionFactory 콩 및 <!--<mvc:annotation-driven/>--> 주석을 제거

<?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 /> 

. 내가 메이븐에서 Thymeleaf 종속성이 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> 

그래서, 나는 하나 개의 구성 라인 같은 간단한 무언가를 놓치고 있음을 확신합니다. 아무도 도와 주시면 고맙겠습니다. 미리 감사드립니다. P.

<!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> 

나는 또한 컨트롤러를 추가하는 시도 :

@Controller 
public final class MainController { 
    @RequestMapping(value = "/") 
    public String displayFirstView() { 
     return "index.html"; 
    } 
} 

를하지만 도움이되지 않았다 내가 비슷한 질문을 가지고보기 때문에 는 또한, web.xml 파일을 포함한다. Solution : applicationContext.xml<mvc:annotation-driven/>을 놓쳤습니다. 여기에 포함 된 MainController과 같은 첫 번째보기 용 컨트롤러가 있어야합니다. 이 문제에 많은 도움을 주신 사용자에게 감사드립니다.

+1

서버 로그를 확인하십시오. mybe 문제점 배포본 – Jens

+0

@Jens Tomcat Catalina 탭의 Hibernate와 관련하여'org.hsqldb.HsqlException : 사용자에게 권한이 없거나 객체가 없습니다. PUBLIC.LANGUAGES_LIST' 만 있지만 Thymeleaf없이 JSP를 사용하면 또한 발생했지만 index.jsp가 표시되었습니다 –

+1

db 액세스 데이터를 확인해야하는 것처럼 보입니다 – Jens

답변

1

당신은 @Controller 주석을 읽을 필요 <mvc:annotation-driven/>가 누락되었습니다. 그것을 추가하십시오.

+0

이전 프로젝트에서 첫 번째보기 (index.jsp)에 Controller를 사용하지 않았기 때문에 도움을 주셔서 감사합니다. AngularJS를 사용하여'RestController's를 사용했기 때문에 어쩌면 제가 새롭습니다. JSP/Thymeleaf로 템플리트 작성하기. 고마워, 이제는 매력처럼 작동합니다. –

+1

나는 그것을 기쁘게 생각한다;) 이전 프로젝트에서 AspectJ로 사용했다면 aspectj autoproxy 같은 것이 있다고 생각한다. 나는 excatly 몰라, 봄 워드 프로세서를보십시오. 그러나 Spring MVC에서 주석 @Controller를 사용해야 할 때 추가해야한다. – Hrabosch

1

아래 링크에서 볼 수 있듯이 viewResolver는 templateEngine을 참조해야합니다.

http://www.thymeleaf.org/doc/articles/thymeleaf3migration.html

+0

viewResolver에 templateEngine :'p : templateEngine-ref = "templateEngine"을 추가했지만 여전히 작동하지 않습니다. 나는 또한 웹을 추가했다.xml' 콘텐츠, 어쩌면 거기에 뭔가 내가 잘못 찾을 수 없습니다 –

+1

그냥 서블릿에 매핑 문제가 아닌가요? '/*' –

+0

@ J.Mengelie주의 해 주셔서 감사 드리며 불행히도 작동하지 않습니다. –