poma już masz więc
package pl.arek.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@EnableWebMvc
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
}
tu chyba się nic nie zmieniło
package pl.arek.web;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class AppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation("pl.arek.web");
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.
addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
ale tak naprawde powinienes tu raczej podac paczke gdzie znajduje się tylko konfiguracja a pozniej za pomoca np @ComponentScan dodac kolejne mapowanie ale w tak by nie zawieralo już tych przeskanowanych paczek. Tak czy inaczej w taki prostacki sposob też działa. Jak pobrałem twoj kod to bez setConfigLocation spring nie odnajdywał twoich klas konfiguracyjnych.
package pl.arek.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MainController {
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String showIndex() {
return "hello world";
}
}
reszte plikow wywaliłem bo nie byla potrzebna.
Pozdrawiam