Swagger – Springfox always generates some response messages (401,403…) by default. How can I remove them?

You should be able to set up the plugin to not use the default response messages. Follow below instructions for different versions. For 1.0.2 or prior new SwaggerSpringMvcPlugin(…) //More config .useDefaultResponseMessages(false) //<– this should be false …; For 2.x new Docket() //More config .useDefaultResponseMessages(false) //<– this should be false …;

Dynamic Selection Of JsonView in Spring MVC Controller

On the off chance someone else wants to achieve the same thing, it actually is very simple. You can directly return aorg.springframework.http.converter.json.MappingJacksonValue instance from your controller that contains both the object that you want to serialise and the view class. This will be picked up by the org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter#writeInternal method and the appropriate view will be … Read more

Http Post with request content type form not working in Spring MVC 3

Unfortunately FormHttpMessageConverter (which is used for @RequestBody-annotated parameters when content type is application/x-www-form-urlencoded) cannot bind target classes (as @ModelAttribute can). Therefore you need @ModelAttribute instead of @RequestBody. If you don’t need to pass different content types to that method you can simply replace the annotation: @RequestMapping(method = RequestMethod.POST) public ModelAndView create(@ModelAttribute UserAccountBean account) { … … Read more

Relation between WebSecurityConfigurerAdapter and ResourceServerConfigurerAdapter

Here is a good answer https://stackoverflow.com/a/28604260, it looks like WebSecurityConfigurerAdapter is an order inferior to the ResourceServerConfigurerAdapter. I have a WebSecurityConfigurerAdapter and a ResourceServerConfigurerAdapter, but the endpoints security configuration is in the ResourceServerConfigurerAdapter under: public void configure(HttpSecurity http) throws Exception { I also have the following configuration: security: oauth2: resource: filter-order: 3 Else the endpoints … Read more

Dynamically changing the @ResponseStatus in annotation driven Spring MVC

@ResponseStatus(HttpStatus.OK) means that the request will return OK if the handling method returns normally (this annotation is redundant for this case, as the default response status is HttpStatus.OK). If the method throws an exception, the annotation does not apply; instead, the status will be determined by Spring using an exception handler. How can I handle … Read more

Get Referer URL in Spring MVC

In Spring MVC 3 you can get it from request, as @BalusC already said: public ModelAndView doSomething(final HttpServletRequest request) { final String referer = request.getHeader(“referer”); … } but there also exists special annotation @RequestHeader which allow to simplify your code to public ModelAndView doSomething(@RequestHeader(value = “referer”, required = false) final String referer) { … }

CharacterEncodingFilter don’t work together with Spring Security 3.2.0

We need to add CharacterEncodingFilter before filters who read request properties for the first time. There is securityFilterChain (stands second. after metrica filter) and we can add our filter inside it. The first filter (inside security chain) who reads properties is CsrfFilter, so we place CharacterEncodingFilter before it. The short solution is: @Configuration @EnableWebMvcSecurity public … Read more

Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result

In order to get it to work right, I have to “drop and drag” the files that I want in my classpath/dependencies into my the WEB-INF/lib folder. It works this way. For some reason, when I try to do it the right way Build path → Configure build path → External jars it just doesn’t … Read more