Spring

Broken caching in a web application

In a Spring Boot Java Web App we had caching set up for several computationally expensive methods. After some time I discovered that the mechanism was apparently broken for those methods, but implementing a new cached method in a completely new service class worked. At first I tried to exclude simple errors as culprits. Method signatures of the cacheable methods were simplified, the @Cacheable method annotation was moved between interface and implementation methods as well as between data repositories and service classes. Another potential error may have come from Springs proxy functionality, which should create a proxy doing the caching for our service. This proved to be the problem - the needed proxy wasn’t generated and I had no clue why. I discovered some warning messages in the application startup logs like 'Bean XYZ is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)'. The proxy stuff for @Cacheable methods is also done via a BeanPostProcessors. It seemed that Spring initialized our service beans long before it manages to initialize the caching mechanism, which deprived them of the caching functionality. By setting a watcher in debug mode in the according class on this log message and tracing back the call stack of our service bean I was able to find out where and understand why our beans were prematurely initialized. In those two resulting classes I implemented a LazyInit feature that initialized our beans after the caching functionality has been initialized and caching started to work again.

I searched for another encoder and found Google’s “GSON” project. I used it to encode the DTO “manually” (without Spring) into a String, sent it to the server and decoded the string there again via GSON (without Spring) into the original object. This time it worked as expected.

Taggings:

Transfer "complex" DTO via REST

I have to transfer a quite complex “data transfer object” (DTO) from an Android app via REST to a backend server. I use the Spring framework (Spring boot) which by default encodes the DTO via Jackson. However, the server never recognizes this object as a whole and assignes it or a subset of it to null.

CRUD operations example using Spring, MVC, Hybernate and Maven

I need an example to better understand of how to operate with these technologies. The interface will be HTML-based. The application will support all CRUD operations: create, read, update, delete. MySQL was used for the database.

Spring/CXF WS controller

A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. The Spring Framework is an open source application framework for the Java platform. Apache CXF is an open-source, fully featured, easy to use Web Services framework. The goal is to correctly configure an MVC controller to communicate with a web service using Spring and Apache CXF.

Spring/CXF WS service

A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. The Spring Framework is an open source application framework for the Java platform. Apache CXF is an open-source, fully featured, easy to use Web Services framework. The goal is to correctly configure a service to be run as a web service using Spring and Apache CXF.

Spring/CXF WS client config

A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. The Spring Framework is an open source application framework for the Java platform. Apache CXF is an open-source, fully featured, easy to use Web Services framework. The goal is to correctly configure a web service client using Spring and Apache CXF.

Spring/CXF WS server config

A web service is typically an application programming interface (API) or Web API that is accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system, hosting the requested service. The Spring Framework is an open source application framework for the Java platform. Apache CXF is an open-source, fully featured, easy to use Web Services framework. The goal is to correctly configure a web service server using Spring and Apache CXF.
Subscribe to Spring