spring-mvc

HTTP Status 405 - Request method 'PUT' not supported

三世轮回 提交于 2020-04-06 02:27:47
问题 I have the following controller: @RestController public class RestaurantController { @Autowired RestaurantService restaurantService; @RequestMapping(value = "/restaurant/", method = RequestMethod.GET) public ResponseEntity<List<Restaurant>> listAllRestaurants() { System.out.println("Fetching all restaurants"); List<Restaurant> restaurants = restaurantService.findAllRestaurants(); if(restaurants.isEmpty()){ return new ResponseEntity<List<Restaurant>>(HttpStatus.NO_CONTENT);//You many decide to

Custom filter breaking @WebMvcTest out of nowhere

断了今生、忘了曾经 提交于 2020-03-25 13:42:07
问题 I'm implementing JWT auth in my application. Everything works fine, but when I run my already existing @WebMvcTests and check for the returned status code, they all fail with an "Actual :403". This is one of my current test suites: @WebMvcTest(controllers = UserController.class) @ContextConfiguration(classes = {JwtServiceImpl.class}) // custom filter dependency class UserControllerTest { /** * Mocked bean because it's a dependency of the SecurityConfiguration */ @MockBean private

Spring MVC Redirect Attribute Messages

本秂侑毒 提交于 2020-03-25 07:51:12
问题 I am having some issues while displaying messages after I have successfully, or unsuccessfully performed some type of CRUD operation (CREATE, DELETE, etc). I have attempted to use Redirect Flash Attributes, although I have found no luck with these and I cannot get the message displaying at all. For example I have declared something like this within my Controller method: public String DeleteAction(Model model, Object object, @RequestParam int id, RedirectAttributes attributes) { // Method

how to call request mapping method level through class level RequestMapping

隐身守侯 提交于 2020-03-20 11:54:24
问题 I did one simple program using spring. I got answer for method level RequestMapping when i did not use class level RequestMapping. But i want to use both class level and method level RequestMapping. This is my controller code package com.birthid; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller

How to cope with x-forwarded-headers in Spring Boot 2.2.0? (Spring Web MVC behind reverse proxy)

社会主义新天地 提交于 2020-03-19 06:05:09
问题 My Spring Boot 2.2.0 application with Spring Web MVC is running behind a reverse proxy. How can Spring cope properly with X-Forwarded-{Prefix,Host,Proto} -headers to recognize the actual request made to the server? 回答1: With Spring Boot <= 2.1.x you had to provide a ForwardedHeaderFilter -Bean. Since Spring Boot 2.2.0 you don't have to do this anymore. Just add server.forward-headers-strategy=NATIVE or server.forward-headers-strategy=FRAMEWORK to your application.properties -file. NATIVE

Hibernate @NotEmpty is deprecated

只谈情不闲聊 提交于 2020-03-18 10:25:53
问题 I am using 5.2.13.Final version of hibernate-core and 5.2.13.Final version of hibernate-validator. @NotEmpty @Column(name = "SSO_ID", unique = true, nullable = false) private String ssoId; @NotEmpty comes in picture when I need the following validation message from the message.properties file when ssoId is empty: NotEmpty.user.ssoId=SSO ID can not be blank. But @NotEmpty is deprecated in the latest version. What is its equivalent? 回答1: Generally, as something is marked as deprecated in a

Spring Boot, static resources and mime type configuration

不羁岁月 提交于 2020-03-18 06:34:17
问题 I'm facing a Spring Boot configuration issue I can't deal with... I'm trying to build an HelloWorld example for HbbTV with Spring Boot, so I need to serve my "index.html" page with mime-type="application/vnd.hbbtv.xhtml+xml" my index.html will be accessed as a static page, for instance http://myserver.com/index.html?param=value. with the following code, no matter how hard I try, I get a text/html content type. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//HbbTV//1.1.1//EN"

Interceptors Or Filters

回眸只為那壹抹淺笑 提交于 2020-03-18 05:53:26
问题 I am working on an Spring Application in which I want to do some security checks like MD5 checking of files, DB checking, Application version check etc. I have read about Interceptors and Filters but still a bit confuse about which one is good to use. Whatever documents I have read, it is specified that filters and interceptors both can be used for Logging and auditing so which one is good for this scenario. Also all this security checks (MD5 checking of files, DB checking, Application

Spring security Cant autowire UserDetailsService

梦想与她 提交于 2020-03-17 12:18:46
问题 I got stuck trying to add authentication from database. Here is error log: 23-Dec-2015 08:24:32.819 SEVERE [localhost-startStop-1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org

java.lang.IllegalStateException: Not a JSON Object

自古美人都是妖i 提交于 2020-03-17 11:13:08
问题 I am trying to get a json response from SonarQube using the SonarQube web API. While assigning the JsonElement into a JsonObject I am getting this error: java.lang.IllegalStateException: Not a JSON Object This is my Java class @Controller public class SonarController { @Autowired JenkinsDataService jenkinsService; @Autowired SonarDataService sonarService; HttpEntity<String> entity; @RequestMapping(value = { "/sonar" }) public void test(HttpServletRequest request, HttpServletResponse response