Spring templateResolver配置

时间:2017-04-09 11:04:29

标签: java spring

我在配置templateResolver时遇到问题。当我尝试获取默认页面时,它的工作正常。当我尝试使用/ someAddress转到页面时我得到

 template might not exist or might not be accessible by any of the configured Template Resolvers

调度-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:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.javapointers.controllers"/>
<bean id="templateResolver"
      class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".html"/>
    <property name="templateMode" value="HTML5"/>
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver"/>
</bean>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>

的HomeController

@Controller
public class HomeController {

@RequestMapping(value="/", method = RequestMethod.GET)
public String viewHome(){
    return "test";
}

@RequestMapping(value="/login", method = RequestMethod.GET)
public String login(){
    return "login";
}

有谁知道正确的配置?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。在我的应用程序中是java类中的另一个bean配置。