Why do I get java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest when I add @Controller to DummyController class?
it.cspnet.firstspringmvc.controller.Main
public static void main(String args[]) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("jpaContext.xml");
Servizi servizi = ctx.getBean(Servizi.class);
Utente utente = new Utente();
utente.setUserName("test");
utente.setPassword("test");
Utente utenteInDb = servizi.login(utente);
for (Ordine ordine : utenteInDb.getOrdini()) {
System.out.println("ordine: " + ordine);
}
}
it.cspnet.firstspringmvc.controller.DummyController
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
@Controller
public class DummyController {
@RequestMapping(value = "/dummy", method = {RequestMethod.GET})
public String get(Model model, HttpServletRequest request) {
return "dummy";
}
}
When I remove the @Controller annotation from DummyController then main prints out the example's fine but if I put it back in then it throws:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest at java.lang.Class.getDeclaredMethods0(Native Method)
I'm using this project:
https://github.com/ivansaracino/spring-mvc-jparepository-example.git
All I've done is add Main and DummyController
@Controllerthe bean is detected and loaded, when removed it isn't loaded and when it isn't loaded the classHttpServletRequestisn't needed.@Controllerin a standalone program.