Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletContext

后端 未结 2 788
滥情空心
滥情空心 2021-01-12 10:35

I am trying to setup the Junit test with the MockMVC.

From this link - \"either must not use the Servlet API or you need to provide it on the classpath\".

I

2条回答
  •  萌比男神i
    2021-01-12 11:26

    Class is not found at runtime but is available at compile time. You need to add the corresponding jar so that it can be found at runtime. I generally use Ivy and in Eclipse I do

    Project -> Properties ->Deployment Assembly -> Add -> java Build Path Enteries -> Ivy -> Finish
    

    There must be something similar for Maven as well.

    Also you need javax.servlet-api only during compile time as the container you are using to run the server will provide the actual APIs at runtime.

提交回复
热议问题