spring-restcontroller

Spring RestController 6 parallel execution? [duplicate]

a 夏天 提交于 2019-12-02 14:10:07
问题 This question already has an answer here : spring boot app only accepts 6 requests why? (1 answer) Closed last month . I developing a SpringBoot-Application. During stress-testing the application shows some strange behaviour according parallel execution. AFAIK there should not be some parallel execution... To test this behaviour i created this RestController: @RestController public class TestController2 { private static int instancecount = 0; @PostConstruct public void con() { System.out

Spring @RestController Get Request Content-Type to response json or html

不打扰是莪最后的温柔 提交于 2019-12-02 07:50:58
how can I take request Content-Type value? We need this to print json response or Html respone. My code is this: @RestController public class GestorController { @RequestMapping(value="/gestores", method = RequestMethod.GET) public Object gestoresHtml(@RequestParam(value="name", required=false, defaultValue="sh14") String name) throws Exception { String json = "prueba json"; String contentType = ????? if(contentType.equals("application/json")){ return json; }else{ ModelAndView mav = new ModelAndView(); mav.setViewName("gestores"); mav.addObject("name", name); return mav; } } } Thanks for all.

@JsonProperty not working for Content-Type : application/x-www-form-urlencoded

浪尽此生 提交于 2019-12-01 21:09:06
The REST API takes input content type : application/x-www-form-urlencoded, when it is mapped to a Java Object, like public class MyRequest { @JsonProperty("my_name") private String myName; @JsonProperty("my_phone") private String myPhone; //Getters and Setters of myName and myPhone. } In form input request, I am setting values of my_name and my_phone but the MyRequest object comes with myName and myPhone as null. I am using Jackson-annotations 2.3 jar Any Suggestions what may be wrong ? I had the same problem recently using SpringMVC and Jackson! In Spring, when you explicit configure your

nested exception is java.lang.IllegalArgumentException: Not a managed type: class

≡放荡痞女 提交于 2019-12-01 18:53:43
I am trying to deploy a Spring-Boot application with Service accessing a JpaRepository which is connecting to PostgreSQL DB at runtime using JPA and Hibernate , refering to connection properties in src/main/resources/application.properties When I am deploying the built .WAR on Tomcat, the Application is failing to start with the error as given in below Error Log. Can somebody please help out what is the meaning of this error? Note I have noted the trouble points in MyServiceImpl and MyRequestBody classes but I am not getting the exact reason for the error, as I am new to Spring framework. The

How to implement Spring Security 4 with both XML and Java config

喜夏-厌秋 提交于 2019-11-30 21:13:31
I am trying to implement Spring-Security 4 into my Spring MVC web and rest app. I added 2 classes to enable Spring Security the java config way. I still want to hold onto my web.xml and not change the entire project to use java config. As soon as I do that, I get the following error: 29-May-2015 08:47:12.826 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined at org.springframework.beans.factory

Return HTTP 204 on null with spring @RestController

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 11:57:12
问题 This returns 200 OK with Content-Length: 0 @RestController public class RepoController { @RequestMapping(value = "/document/{id}", method = RequestMethod.GET) public Object getDocument(@PathVariable long id) { return null; } } Simply put I'd like it to return 204 No Content on null. Is there a way to force spring-mvc/rest to return 204 on null not 200? I dont want to change every rest method to return ResponseEntity or something like that, only map null to 204 回答1: Of course yes. Option 1 :

Difference between @RestController and @RepositoryRestController

拥有回忆 提交于 2019-11-30 11:34:27
What is the typical use case code that shows the difference between those two annotations - meaning the @RestController and the @RepositoryRestController - ? According to the annotation the RepositoryRestController is a way to provide custom controllers that still take advantage of spring data rest functionality http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers Sometimes you may want to write a custom handler for a specific resource. To take advantage of Spring Data REST’s settings, message converters, exception handling, and

lost one day for a date

大城市里の小女人 提交于 2019-11-30 08:10:16
问题 On client side, i use dd/MM/yyyy date format. The field use a twitter bootstrap 3 datetime picker (https://eonasdan.github.io/bootstrap-datetimepicker/) I enter via twitter bootstrap 3 datetime picker 24/07/2015 in my json i sent, i see: birthdate: "24/07/2015" In my dto, i do @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy") private Date birthdate; When i receive the date on the server, in my dto see: 23/07/2015 19:00 One day is lost. Any explication? 回答1: According to

Could not verify the provided CSRF token because your session was not found in spring security

烂漫一生 提交于 2019-11-30 06:04:16
I am using spring security along with java config @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/api/*").hasRole("ADMIN") .and() .addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class) .exceptionHandling() .authenticationEntryPoint(restAuthenticationEntryPoint) .and() .formLogin() .successHandler(authenticationSuccessHandler) .failureHandler(new SimpleUrlAuthenticationFailureHandler()); I am using PostMan for testing my REST services. I get 'csrf token' successfully and I am able to login by using X-CSRF

SpringFox Docket per controller not working in spring boot

久未见 提交于 2019-11-29 12:38:13
In my spring boot application, I have multiple Rest Controllers and need to generate swagger for each controller seperately. By using below Docket config for each controller in my spring boot application class, i am able to download controller specific swagger by going to /v2/api-docs?group=ai where i = 1 to n However in swagger-ui.html, when i select a1(/v2/api-docs?group=a1), it shows path as "/api/a1/a1", while selecting a2(/v2/api-docs?greoup=a2), it shows correct path i.e. /api/a2 I have tried changing in Docket ,paths regex to absolute e.g. "api/a1" etc but that didn't help. @Bean public