Introduction This is the second post on the series about Spring Bean Scopes. In the previous tutorial we saw that there were issues rising when a Prototype scoped Bean was injected in a Singleton scoped Bean. The main problem is that autowired Prototypes will be injected when the Singleton Bean is instantiated (which happens only once) thus even though they are prototypes in reality they’ll behave as singletons. The next code highlights this behavior: [crayon-5b0875be2b89f527449027/] In the previous example, although the object requested with getAutowiredSample is defined with a Prototype scoped Bean, the instance of the object returned in both […]

Spring Bean Scopes: Singleton with Prototypes

Introduction This tutorial shows the different scopes you can assign to a Bean or a Component in Spring Framework. It’s important to understand that a Bean definition is just a recipe to create instances of a class following the definition of this recipe. This recipe can be then used one or more times during the life cycle of the application to create an instance of the Bean. The Bean scope is one of the main characteristics of the Bean configuration in Spring. The scope will indicate when and how is the object for the Bean definition going to be instantiated. […]

Spring Bean Scopes: Guide to understand the different Bean scopes

Spring-Data + MongoDB
Introduction Spring Data makes really quick and easy the process of working with data entities, offering a specific implementation for MongoDB. You can merely define queries by creating interfaces with methods following a naming convention or annotating them with @Query and Spring will automagically generate an implementation for you. Most of the times this is enough for simple CRUD and query operations and there is no need to define additional methods. This will allow you to get up and running really quickly avoiding to type boilerplate code. However, there are many times where this is not enough and the repository […]

Spring Data MongoDB: Custom repository implementation

build.gradle script 5
Introduction In this post I’ll show you how to serve an Angular (>2) frontend application using a Java Spring Boot application as the backend and static page web server, and a Gradle script to perform automated build and deploy tasks both for Spring and Angular. Requirements The technology stack required for this tutorial is: Node.js Angular CLI Gradle The main goal is to achieve a npm install + build that integrates with Java’s gradle build and deploys the distribution files into Spring’s static resources directory. You could replace Angular CLI for any other Frontend build tool / framework such as React. […]

Angular + Spring Boot integration using Gradle

Spring + EclipseLink JPA 3
Spring Data JPA By default Spring uses Hibernate as the default JPA vendor. Although Hibernate is a good choice, some of us may prefer to use EclipseLink as it was supposed to be the reference implementation for the Java Persistence JSR. In this tutorial we will setup a Spring-Boot application to use EclipseLink with a PostgreSQL database, although it can be used with any other database. Fixing dependencies In order to use EclipseLink, we must remove Hibernate’s entity manager from the classpath in order to avoid problems. This is a matter of adding an exclusion to your application’s Gradle script or […]

Spring Data JPA + EclipseLink: Configuring Spring-Boot to use EclipseLink ...