org.springframework.web.servlet.PageNotFound noHandlerFound

时间:2014-06-02 19:28:44

标签: spring-mvc thymeleaf

我在项目中使用Thyemeleaf。 这是我的web.xml

    <web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <display-name>SpringUI</display-name>
  <!-- Bootstrap the root context -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext -->
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
         org.springframework.web.context.support.AnnotationConfigWebApplicationContext
      </param-value>
    </context-param>

    <!-- @Configuration classes or package -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mdm.config.WebAppConfiguration</param-value>
    </context-param>

    <!-- Spring servlet -->
    <servlet>
        <servlet-name>springServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springServlet</servlet-name>
        <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>

</web-app>

这是我的应用配置文件

 @EnableWebMvc
    @Configuration
    @ComponentScan("com.mdm.controller")
    public class WebAppConfiguration extends WebMvcConfigurerAdapter {
@Bean
@Description("Thymeleaf template resolver ")
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
    templateResolver.setPrefix("/WEB-INF/pages/");
    templateResolver.setSuffix(".jsp");
    //templateResolver.setTemplateMode("HTML5");

    return templateResolver;
}

@Bean
@Description("Thymeleaf template engine with Spring integration")
public SpringTemplateEngine templateEngine() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver());

    return templateEngine;
}

@Bean
@Description("Thymeleaf view resolver")
public ThymeleafViewResolver viewResolver() {
    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(templateEngine());

    return viewResolver;
}

@Bean
@Description("Spring message resolver")
public ResourceBundleMessageSource messageSource() {  
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();  
    messageSource.setBasename("/WEB-INF/resources/i18n/messages");  

    return messageSource;  
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
}

这是我的控制器

@Controller
public class PersonController 
{   

@RequestMapping(value="/personcreate", method = RequestMethod.GET)
public String initForm(ModelMap model,HttpSession session)
{
    PersonTO personTO = new PersonTO();
    IdentifierBean defaultIdBean=new IdentifierBean();
    model.addAttribute("personTO", personTO);
    model.addAttribute("identifierBean", defaultIdBean);
    session.setAttribute("modelMap", model);
}
    return "personinfo";
}

当我尝试加入url ip:port / SpringUI / spring / personcreate时,会出现以下错误

Jun 03, 2014 12:46:14 AM org.springframework.web.servlet.PageNotFound noHandlerFound

警告:在DispatcherServlet中找不到带有URI [/ SpringUI / spring / personcreate]的HTTP请求的映射,其名称为&#39; springServlet&#39; 我在这里做的错误是什么?

0 个答案:

没有答案