Spring MVC RequestMappingHandlerMapping - 没有找到处理程序方法

时间:2017-09-22 10:39:42

标签: java spring spring-mvc

我认为我的配置没问题,但我一直收到同样的错误“没找到处理程序方法”。

错误:

10:55:46.284 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /WEB-INF/views/html/products/list.html
10:55:46.285 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/WEB-INF/views/html/products/list.html]
10:55:46.285 [http-nio-8080-exec-3] WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/store/WEB-INF/views/html/products/list.html] in DispatcherServlet with name 'spring-web'
10:55:46.285 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request

我的web.xml如下:

<servlet>
    <servlet-name>spring-web</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

我的spring-web-servlet.xml

<context:component-scan base-package="com.ecommerce.config" />

My SprinWebConfig.java

@EnableWebMvc
@Configuration
@ComponentScan({ "com.ecommerce.web", "com.ecommerce.service", "com.ecommerce.dao", "com.ecommerce.exception", "com.ecommerce.validator" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/html/");
        viewResolver.setSuffix(".html");
        return viewResolver;
    }

    @Bean
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource rb = new ResourceBundleMessageSource();
        rb.setBasenames(new String[] {"messages/messages", "messages/validation"});
        return rb;
    }
}

ProductController.java

@Controller
public class ProductController {

    private final Logger logger = LoggerFactory.getLogger(ProductController.class);

    @GetMapping("/")
    public String index(Model model) {
        logger.debug("index()");
        return "redirect:/products";
    }

    @GetMapping("/products")
    public String showAllProducts(Model model) {
        logger.debug("showAllProducts()");

        //Here I'm constructing a list named products

        model.addAttribute("products", products);

        return "products/list";
    }
}

所以,我看不出我的问题在哪里。你能帮帮忙吗?感谢

0 个答案:

没有答案