How to disable spring-data-mongodb autoconfiguration in spring-boot

This is how I do it: @SpringBootApplication(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) or as suggested by Dan Oak: spring.autoconfigure.exclude= \ org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\ org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration

Implementing custom methods of Spring Data repository and exposing them through REST

After two days, I have solved in this way. Custom Repository Interface: public interface PersonRepositoryCustom { Page<Person> customFind(String param1, String param2, Pageable pageable); } Custom Repository Implementation public class PersonRepositoryImpl implements PersonRepositoryCustom{ @Override public Page<Person> customFind(String param1, String param2, Pageable pageable) { // custom query by mongo template, entity manager… } } Spring Data Repository: … Read more

How to test Spring’s declarative caching support on Spring Data repositories?

If you want to test a technical aspect like caching, don’t use a database at all. It’s important to understand what you’d like to test here. You want to make sure the method invocation is avoided for the invocation with the very same arguments. The repository fronting a database is a completely orthogonal aspect to … Read more

How to consume Page response using Spring RestTemplate

new TypeReference<Page<StoryResponse>>() {} The problem with this statement is that Jackson cannot instantiate an abstract type. You should give Jackson the information on how to instantiate Page with a concrete type. But its concrete type, PageImpl, has no default constructor or any @JsonCreators for that matter, so you can not use the following code either: … Read more

How to use Spring managed Hibernate interceptors in Spring Boot?

There’s not a particularly easy way to add a Hibernate interceptor that is also a Spring Bean but you can easily add an interceptor if it’s managed entirely by Hibernate. To do that add the following to your application.properties: spring.jpa.properties.hibernate.ejb.interceptor=my.package.MyInterceptorClassName If you need the Interceptor to also be a bean you can create your own … Read more

Spring Data MongoDB Date Between

Do not include the ‘and(“startDate”)‘ part in your criteria. Instead of : query.addCriteria(Criteria.where(“startDate”).gte(startDate).and(“startDate”).lt(endDate)); You should use: query.addCriteria(Criteria.where(“startDate”).gte(startDate).lt(endDate)); When you include the ‘and(“startDate”)’ part, Mongo see’s it as two different entries on the same property.

Dynamic spring data jpa repository query with arbitrary AND clauses

You can use Specifications that Spring-data gives you out of the box. and be able to use criteria API to build queries programmatically.To support specifications you can extend your repository interface with the JpaSpecificationExecutor interface public interface CustomerRepository extends SimpleJpaRepository<T, ID>, JpaSpecificationExecutor { } The additional interface(JpaSpecificationExecutor ) carries methods that allow you to execute … Read more