Błąd w aplikacji webowej. Czy ktoś wie jak naprawić mapowanie w Dispatcherze?

0

Witam!
Oto mój kod:
SpringWebConfig.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.kamil.config;


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

/**
 *
 * @author Kamil
 */
@Configuration
@ComponentScan(basePackages={"pl.kamil"})
@EnableWebMvc
public class SpringWebConfig extends WebMvcConfigurerAdapter{

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       
    }
    @Bean
    public ViewResolver viewResolver(){
        InternalResourceViewResolver vr = new InternalResourceViewResolver();
        vr.setViewClass(JstlView.class);
        vr.setPrefix("/WEB-INF/View/");
        vr.setSuffix(".jsp");
       
        return vr;
    }
}


ContactAppDispatcher... .java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.kamil.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 *
 * @author Kamil
 */
public class ContactAppDispatcherServlerInitiazer extends AbstractAnnotationConfigDispatcherServletInitializer{

    @Override
    protected Class<?>[] getRootConfigClasses() {
       return new Class[]{SpringRootConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
      return new Class[]{SpringWebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
      return new String[]{"/"};
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext); //To change body of generated methods, choose Tools | Templates.
    }

    
}

TestController.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.kamil.controller;

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

/**
 *
 * @author Kamil
 */
@Controller
public class TestController {
    
    @RequestMapping("/test/hello")
    public String helloWorld(){
        return "hello";
    }

}


podczas odpalania projektu wyrzuca mi blad w Apache Tomcat:
"06-May-2018 2159.657 WARNING [http-nio-8080-exec-18] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/ContactApp/] in DispatcherServlet with name 'dispatcher'"

a w przeglądarce "HTTP Status 404- The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

Czy ktoś wie jak to rozwiązać?

0

Niby czemu miałby obsługiwać url /ContactApp ? Gdzie masz taką ścieżkę w kodzie?

0
jarekczek napisał(a):

Niby czemu miałby obsługiwać url /ContactApp ? Gdzie masz taką ścieżkę w kodzie?

no właśnie nigdzie :/

0
morgutrin napisał(a):

oraz http://localhost:8080/ContactApp/test/hello

morgutrin znalazłeś rozwiązanie? bo borykam się z tym samym problemem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1