Weird Spring Mock error

Posted & filed under Spring.

I’ve been looking into a weird Spring testing error from this code:

MockMultipartHttpServletRequest req = new MockMultipartHttpServletRequest();
req.addFile(new MockMultipartFile("file","test1.html","text/html", fi));
req.setContentType("multipart/form-data");
req.setMethod("POST");
req.setRequestURI("/en/uploadaction");
handlerAdapter.handle(req, response, controller);

which threw this exception:

java.lang.AbstractMethodError:
org.springframework.mock.web
MockMultipartHttpServletRequest.getFiles(Ljava/lang/String;)Ljava/util/List;

Turns out I was using spring-mock-2.0.8 when in fact I should have been using the new Spring test dependency:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
  <version>3.0.5-RELEASE</version>
  <scope>test</scope>
</dependency>

 

Spring templates for functionality mix ‘n match

Posted & filed under Spring.

I’ve knocked up some Spring web applications that show how to use basic functionality in Spring. Each one is contained in a git branch and has just the right amount of maven clutter to make it work. The functionality in each branch so far is:

You can get the source from my github repo.