I was trying to write unit test for Servlet using sprint-test using mock object
my maven dependency is:
According to the Spring Framework Reference for Testing you should be using annotations to autowire your mocks. The example in the spring reference:
`
@WebAppConfiguration
@ContextConfiguration
public class WacTests {
@Autowired WebApplicationContext wac; // cached
@Autowired MockServletContext servletContext; // cached
@Autowired MockHttpSession session;
@Autowired MockHttpServletRequest request;
@Autowired MockHttpServletResponse response;
@Autowired ServletWebRequest webRequest;
//...
}
`
A different example (without annotations) can be found here
I had a similar issue and solved it by adding this dependency to my pom and there is no need to change your javaee-api to javax.servlet
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
<version>6.1.11</version>
</dependency>
I need to replace dependency for javaee-api with javax.selvlet-api as below:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>