No HandlerMappings in "DispatcherServlet" Servlet: Use Default Parameters

I am trying to execute a basic webapp project using Spring MVC (STS 3.7.0 starter project). Java 1.7
WebConfig.java

package com.terafast;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.terafast")
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public InternalResourceViewResolver getInternalViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/view/");
        resolver.setSuffix(".jsp");

        return resolver;
    }
}

      

WebAppInitializer.java

package com.terafast;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        WebApplicationContext context = getContext();
        servletContext.addListener(new ContextLoaderListener(context));
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("*.html");
    }

    private AnnotationConfigWebApplicationContext getContext() {
        AnnotationConfigWebApplicationContext context = new  AnnotationConfigWebApplicationContext();
        context.setConfigLocation("com.terafast.WebConfig");

        return context;
    }

}

      

HomeController

package com.terafast.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
    @RequestMapping(value = "/index")
    public String index(Model model) {

        return "welcome";
    }
}

      

I created welcome.jsp at webapp / WEB-INF / view / path. When I run the project as a server, I got nothing on http: // localhost: 8080 / TEM / . I also got nothing when I used http: // localhost: 8080 / TEM / index.html .

18:18:29.911 [http-nio-8080-exec-4] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/TEM/index] in DispatcherServlet with name 'DispatcherServlet' 
18:18:29.911 [http-nio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

      

enter image description here Can someone please explain what the problem is?

+3


source to share


1 answer


Hey I ran into the same problem, what you can do is go to your project properties -> DeploymentAssembly and then add your DispatcherServlet library wherever it is.



This will solve your problem.

0


source







All Articles