Witam, staram się konfigurować Springa w Javie, jednakże napotykam problem, gdyż dostaje 404.
Klasa ApplicationInitializer :
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {RootConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?> [] {ServletConfigClass.class};
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
Klasa RootConfig :
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@ComponentScan(basePackages = {"bartek"}, excludeFilters =
{@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
class RootConfig {
}
Klasa DispatcherServletConfig :
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.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan("bartek.controllers")
class ServletConfigClass {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
}
Controller :
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String homePage() {
return "home";
}
}
I wywala 404, gdyby ktoś mógł wytłumaczyć gdzie jest błąd byłbym bardzo wdzieczny. Pozdrawiam