What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?

I have just asked the Spring Cloud guys and thought I should share the info I have here. bootstrap.yml is loaded before application.yml. It is typically used for the following: when using Spring Cloud Config Server, you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml some encryption/decryption information Technically, bootstrap.yml is loaded by a parent Spring … Read more

Populating Spring @Value during Unit Test

If possible I would try to write those test without Spring Context. If you create this class in your test without spring, then you have full control over its fields. To set the @value field you can use Springs ReflectionTestUtils – it has a method setField to set private fields. @see JavaDoc: ReflectionTestUtils.setField(java.lang.Object, java.lang.String, java.lang.Object)

Spring RestTemplate GET with parameters

To easily manipulate URLs / path / params / etc., you can use Spring’s UriComponentsBuilder class to create a URL template with placehoders for the parameters, then provide the value for those parameters in the RestOperations.exchange(…) call. It’s cleaner than manually concatenating strings and it takes care of the URL encoding for you: HttpHeaders headers … Read more

Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml defines the beans for the “root webapp context”, i.e. the context associated with the webapp. The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet’s app context. There can be many of these in a webapp, one per Spring … Read more

How to use OrderBy with findAll in Spring Data

public interface StudentDAO extends JpaRepository<StudentEntity, Integer> { public List<StudentEntity> findAllByOrderByIdAsc(); } The code above should work. I’m using something similar: public List<Pilot> findTop10ByOrderByLevelDesc(); It returns 10 rows with the highest level. IMPORTANT: Since I’ve been told that it’s easy to miss the key point of this answer, here’s a little clarification: findAllByOrderByIdAsc(); // don’t miss … Read more

@RequestParam vs @PathVariable

@PathVariable is to obtain some placeholder from the URI (Spring call it an URI Template) — see Spring Reference Chapter 16.3.2.2 URI Template Patterns @RequestParam is to obtain a parameter from the URI as well — see Spring Reference Chapter 16.3.3.3 Binding request parameters to method parameters with @RequestParam If the URL http://localhost:8080/MyApp/user/1234/invoices?date=12-05-2013 gets the … Read more

Difference between spring @Controller and @RestController annotation

@Controller is used to mark classes as Spring MVC Controller. @RestController is a convenience annotation that does nothing more than adding the @Controller and @ResponseBody annotations (see: Javadoc) So the following two controller definitions should do the same @Controller @ResponseBody public class MyController { } @RestController public class MyRestController { }

Only using @JsonIgnore during serialization, but not deserialization

Exactly how to do this depends on the version of Jackson that you’re using. This changed around version 1.9, before that, you could do this by adding @JsonIgnore to the getter. Which you’ve tried: Add @JsonIgnore on the getter method only Do this, and also add a specific @JsonProperty annotation for your JSON “password” field … Read more