Konfiguracja Springa w javie

0

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

0

Log ze startu tomcata i log z tego co sie dzieje jak wchodzisz pod ten URL.

0

11-Jan-2016 16:05:48.488 WARNING [http-nio-8084-exec-3] org.springframework.web.servlet.DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI [/BartekWebstore2/] in DispatcherServlet with name 'dispatcher' <--- to wyrzuca mi w logach po wejsciu na stronke

Skąd wział się tam DispatcherServlet o nazwie 'dispatcher' to ja nie rozumiem.

0

Rozumiem że nie mogłeś wrzucić całego logu ze startu? To byśmy widzieli przynajmniej co ten spring załadował. No ale skoro nie wrzuciłeś to wróżenie z fusów: pod jaki adres wchodzisz? http://localhost/BartekWebstore2 ? A pod rootem co jest? Pod samym http://localhost?

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