spring-web

How to prevent spring-boot autoconfiguration for spring-web?

≡放荡痞女 提交于 2019-12-02 21:57:20
I'm using spring-boot and added spring-web dependency in maven pom, to make use of RestTemplate . Now spring tries to initialize an EmbeddedServletContext . How can I prevent it? Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)

Generated Swagger REST client does not handle + character correctly for query parameter

ぃ、小莉子 提交于 2019-12-02 05:18:26
问题 I have this Spring REST controller method: @ApiOperation("My method") @RequestMapping(method = RequestMethod.POST, value = "/myMethod") public void myMethod(@RequestParam("myParam") String myParam) { ... } The REST client is generated using swagger codegen CLI with language Java and library resttemplate : public void myMethod(String myParam) throws RestClientException { ... return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType,

Generated Swagger REST client does not handle + character correctly for query parameter

流过昼夜 提交于 2019-12-02 02:12:17
I have this Spring REST controller method: @ApiOperation("My method") @RequestMapping(method = RequestMethod.POST, value = "/myMethod") public void myMethod(@RequestParam("myParam") String myParam) { ... } The REST client is generated using swagger codegen CLI with language Java and library resttemplate : public void myMethod(String myParam) throws RestClientException { ... return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); } And the source code for ApiClient#invokeAPI - which is also generated - is:

Spring Boot Mapping Validation Codes to MessageSource Message

旧巷老猫 提交于 2019-12-01 09:30:32
Problem: I am trying to use as much Spring Boot Auto-configuration as possible to reduce boiler plate code. I cannot get the Spring Validation codes to automatically map to my externalized messages.properties. It will only work if I add my own LocalValidatorFactoryBean and use the fully qualified javax constraint message. Goal I want to override the defaultMessage for @javax.validation.constraints.NotNull globally in my application based on Spring Validation code s. The first thing I did was register this bean...do I really have to? I see Spring Boot has one but it doesn't seem to correlate to

Spring Boot Mapping Validation Codes to MessageSource Message

…衆ロ難τιáo~ 提交于 2019-12-01 08:12:55
问题 Problem: I am trying to use as much Spring Boot Auto-configuration as possible to reduce boiler plate code. I cannot get the Spring Validation codes to automatically map to my externalized messages.properties. It will only work if I add my own LocalValidatorFactoryBean and use the fully qualified javax constraint message. Goal I want to override the defaultMessage for @javax.validation.constraints.NotNull globally in my application based on Spring Validation code s. The first thing I did was

Prototype Bean doesn't get autowired as expected

☆樱花仙子☆ 提交于 2019-11-30 08:03:24
TestController.java @RestController public class TestController { @Autowired private TestClass testClass; @RequestMapping(value = "/test", method = RequestMethod.GET) public void testThread(HttpServletResponse response) throws Exception { testClass.doSomething(); } } TestClass.java @Component @Scope("prototype") public class TestClass { public TestClass() { System.out.println("new test class constructed."); } public void doSomething() { } } As you can see, I'm trying to figure out whether a new TestClass has been injected when visit "xxx/test". "new test class constructed." got printed only

Spring Rest Controller: how to selectively switch off validation

自古美人都是妖i 提交于 2019-11-29 13:42:27
In my controller I have a method for creating an entity import javax.validation.Valid; ... @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity<?> create(@Valid @RequestBody RequestDTO requestDTO) { ... with import org.hibernate.validator.constraints.NotEmpty; ... public class RequestDTO @NotEmpty // (1) private String field1; //other fields, getters and setters. I want to add a controller method update(@Valid @RequestBody RequestDTO requestDTO) but in this method it should be allowed for field1 to be empty or null, i.e. the line

How to test DeferredResult timeoutResult

我只是一个虾纸丫 提交于 2019-11-29 05:56:17
I'm implementing long polling as per the Spring blog from some time ago . Here my converted method with same response signature as before, but instead of responding immediately, it now uses long polling: private Map<String, DeferredResult<ResponseEntity<?>>> requests = new ConcurrentHashMap<>(); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) public DeferredResult<ResponseEntity<?>> poll(@PathVariable("uuid") final String uuid) { // Create & store a new instance ResponseEntity<?> pendingOnTimeout = ResponseEntity.accepted().build(); DeferredResult<ResponseEntity<?>>

Spring RestTemplate and generic types ParameterizedTypeReference collections like List<T>

徘徊边缘 提交于 2019-11-29 05:28:51
An Abstract controller class requires List of objects from REST. While using Spring RestTemplate its not mapping it to required class instead it returns Linked HashMAp public List<T> restFindAll() { RestTemplate restTemplate = RestClient.build().restTemplate(); ParameterizedTypeReference<List<T>> parameterizedTypeReference = new ParameterizedTypeReference<List<T>>(){}; String uri= BASE_URI +"/"+ getPath(); ResponseEntity<List<T>> exchange = restTemplate.exchange(uri, HttpMethod.GET, null,parameterizedTypeReference); List<T> entities = exchange.getBody(); // here entities are List<LinkedHashMap

Prototype Bean doesn't get autowired as expected

為{幸葍}努か 提交于 2019-11-29 05:21:39
问题 TestController.java @RestController public class TestController { @Autowired private TestClass testClass; @RequestMapping(value = "/test", method = RequestMethod.GET) public void testThread(HttpServletResponse response) throws Exception { testClass.doSomething(); } } TestClass.java @Component @Scope("prototype") public class TestClass { public TestClass() { System.out.println("new test class constructed."); } public void doSomething() { } } As you can see, I'm trying to figure out whether a