Tag: Spring
-
Spring: Component Scan Selected Classes
PROBLEM Let’s assume we have a package with the following classes where each class is either annotated with Spring’s @Service, @Component, @Controller or @Repository. When writing unit test, we want Spring to component scan class A and class B. SOLUTION Before we begin, we configure Log4j to log Spring in debug level. Step 1 If… Read More…
-
Rest Template: Could Not Extract Response – No Suitable HttpMessageConverter Found for Response Type [X] and Content Type [application/json;charset=UTF-8]
PROBLEM When invoking a web service using RestTemplate:- … the following exception occurs:- SOLUTION If the content type is JSON, add the following dependency:- Read More…
-
Spring Data JPA: Requested bean is currently in creation: Is there an unresolvable circular reference?
PROBLEM Let’s assume we have the following Spring Data JPA repository… … this repository has some custom implementation… … this custom implementation depends on the original repository to reuse existing APIs… When we run the code, we get the following exception:- SOLUTION To fix the circular reference problem, instead of auto-wiring ProjectRepository using the constructor,… Read More…
-
Akka: Spring Integration
PROBLEM To create Spring-managed prototype-scoped actors. SOLUTION The key to this solution is to create a custom implementation of IndirectActorProducer. From the documentation:- “…This interface defines a class of actor creation strategies deviating from the usual default of just reflectively instantiating the Actor subclass. It can be used to allow a dependency injection framework to… Read More…
-
Spring MVC: Handling Joda Data Types as JSON
PROBLEM Let’s assume we have the following bean that contains Joda’s LocalDate and LocalDateTime objects:- This simple Spring MVC rest controller creates this bean and returns the JSON data back to the client:- By default, the generated JSON looks like this:- How do we nicely format these values and still retain the correct data types… Read More…
-
Spring: Invoking Stored Procedure
PROBLEM There are many ways to skin a cat… so is invoking a stored procedure using Spring. Let’s assume we want to invoke the following stored procedure that accepts 3 arguments (person ID, start date, end date):- This stored procedure returns a result set where each row contains a person ID, a date and a… Read More…