I am using Spring for MVC tests Here is my test class Here is the MVC config Here is the security config When I run my test it fails with the message: I understand that it fails due to the fact that the url is protected with spring security, but when I run my application I can access that url
Tag: spring-boot
Read properties by dynamic keys in spring boot
I wanted to know if there is any way in Spring Boot to read property values from properties file by using Dynamic Keys. I know properties can be put in application.properties and can be read using @Value(“propertyKey”) But my keys are going to be dynamic. I know about @PropertySource to read prope…
Jackson serializes a ZonedDateTime wrongly in Spring Boot
I have a simple application with Spring Boot and Jetty. I have a simple controller returning an object which has a Java 8 ZonedDateTime: In my RestController I simply have: I was expecting the ZonedDateTime to be formatted according to the ISO format, but instead I am getting a whole JSON dump of the class li…
Spring boot mapping static html
I want to create spring boot web application. I have two static html files: one.html, two.html. I want to map them as follows without using template engines (Thymeleaf). How to do that? I have tried many ways to do that, but I have 404 error or 500 error (Circular view path [one.html]: would dispatch back to …
Spring Boot Integration test random free port
I am able to get Spring Boot integration to generate a random free port to launch itself on. But I also need a free port for Redis. Any ideas on how to achieve this? Answer You can use Spring Framework’s SocketUtils to get an available port:
Netflix Feign – Propagate Status and Exception through Microservices
I’m using Netflix Feign to call to one operation of a Microservice A to other other operation of a Microservice B which validates a code using Spring Boot. The operation of Microservice B throws an exception in case of the validation has been bad. Then I handled in the Microservices and return a HttpSta…
RabbitMQ java client stops consuming messages
My application consumes some messages from RabbitMQ and processes them. I have about 10 queues and each queue has up to ten consumers (threads). I have a prefetch of 5. I’m running my setup in Heroku using the CloudAMQP plugin (RabbitMQ as a service). I’m running with the default heartbeat and con…
Enable HTTP2 with Tomcat in Spring Boot
Tomcat 8.5, which will be the default in Spring Boot 1.4, supports HTTP/2. How can HTTP/2 be enabled in a Spring Boot application? Answer The most elegant and best-performing way to enable HTTP/2 with a Spring Boot application follows here. First, as mentioned in Andy Wilkinson’s answer, you need to ena…
mock resttemplate to test a service as restFul client
I have a service class, written in spring, with some methods. One of this acts as a restful consumer like below: I want to use Mockito to mock my service, but every method that interacts with restful server instance a new RestTemplate. I’ve to create a static class to Inject it into my service? Answer O…
Using @RequestParam for multipartfile is a right way?
I’m developing a spring mvc application and I want to handle multipart request in my controller. In the request I’m passing MultiPartFile also, currently I’m using @RequestParam to get the file parameter, the method look like, Above code works well in my service and the file is getting on th…