Spring boot error:java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

The solution can vary based on actual incompatibility root cause. The best way how to investigate such the issue is to follow this line: Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy and put breakpoint into constructor of class ‘TypeNotPresentExceptionProxy’ (there is only one). After execution in debug mode you should see what exactly is wrong and based on … Read more

org.springframework.web.multipart.MultipartException: The current request is not a multipart request

Check whether you have added CommonsMultipartResolver in Spring-Servlet.xml. <bean id=”multipartResolver” class=”org.springframework.web.multipart.commons.CommonsMultipartResolver”/> Then, add the enctype to multipart/form-data in your form <form id=”fileupload” method=”post” enctype=”multipart/form-data”> Finally in Controller, Request > MultipartHttpServletRequest @RequestMapping(value = “/profileimageupload”, method = RequestMethod.POST) public ModelAndView uploadProfileImage(MultipartHttpServletRequest request) {} Dependencies commons-fileupload.jar commons-io.jar

Return literal JSON strings in spring mvc @ResponseBody

This works with Jackson 2 (at least): @Controller public class YourController { @RequestMapping(..) public @ResponseBody Json get() { return new Json(“{ \”attr\” : \”value\” }”); } } class Json { private final String value; public Json(String value) { this.value = value; } @JsonValue @JsonRawValue public String value() { return value; } } Not particularly pretty … Read more

spring mvc get all request mappings

I am replicating one of my previous answers here: If you are using Spring 3.1 this handlerMapping component is an instance of RequestMappingHandlerMapping, which you can query to find the handlerMappedMethods and the associated controllers, along these lines(if you are on an older version of Spring, you should be able to use a similar approach): … Read more

@ModelAttribute annotation, when to use it?

You don’t need @ModelAttribute (parameter) just to use a Bean as a parameter For example, these handler methods work fine with these requests: @RequestMapping(“/a”) void pathA(SomeBean someBean) { assertEquals(“neil”, someBean.getName()); } GET /a?name=neil @RequestMapping(value=”/a”, method=RequestMethod.POST) void pathAPost(SomeBean someBean) { assertEquals(“neil”, someBean.getName()); } POST /a name=neil Use @ModelAttribute (method) to load default data into your model … Read more

ContentCachingResponseWrapper Produces Empty Response

After couple of hours of struggling, I’ve finally found the solution. In short, ContentCachingResponseWrapper.copyBodyToResponse() should be called in the end of the filter method. ContentCachingResponseWrapper caches the response body by reading it from response output stream. So, the stream becomes empty. To write response back to the output stream ContentCachingResponseWrapper.copyBodyToResponse() should be used.

AngularJS with Spring-mvc [closed]

Two cases: Your architecture is full client-side: In this case the integration is very natural. Spring MVC exposes your service as a REST (JSON/XML) and your client application with AngularJS consumes your JSON. Here the .war application (Spring MVC) must be deployed in a servlet container (e.g. Tomcat) and your client application can be deployed … Read more

Isolated Controller Test can’t instantiate Pageable

Original answer: The problem with pageable can be solved by providing a custom argument handler. If this is set you will run in a ViewResolver Exception (loop). To avoid this you have to set a ViewResolver (an anonymous JSON ViewResolver class for example). mockMvc = MockMvcBuilders.standaloneSetup(controller) .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) .setViewResolvers(new ViewResolver() { @Override public View resolveViewName(String … Read more