Spring Cloud Bus Example

Here I am going to build an application to show how to use Spring Cloud Bus. Let’s say you have multiple applications reading properties using Spring Cloud Config from centralized configuration files (for example, from Git repository). Spring Cloud Config is where you can have not only your all configurations centrally managed but also you can refresh them dynamically and which in turn can be picked by your referencing applications from the very next moment. So in central configurations using Spring Cloud Config, for each module if there is any…

Continue

Spring Centralized Runtime Properties Configuration without refreshing the Client

Introduction This tutorial walks you through the process of consuming the configurations from the Spring cloud config server. So I will setup a config server and build a client application consumes the configuration on startup and then refreshes the configuration without restarting the client. Let’s say you have some configuration values, in application properties or yaml/yml files, which may be changed during runtime and it is not possible always to restart your application and change the configuration values. Here Spring configuration helps you to externalize our properties or configurations.

Continue

Conditional Statement in Spring Config

Sometimes we may need to have some conditional statement in Spring config XML file depending upon some variables value. Think of a situation when you are using JPA in your application and your application may have two persistence units in Spring XML config file and you need to connect to one of them depending upon the environments. Here conditional statement in Spring config comes to rescue. For example, when you write code in your local system and want to test the application then you do not want to connect to…

Continue

Compound Property Names in Spring

With this example I will show you how compound or nested property names work in Spring application. Compound or nested property names are perfectly legal when setting bean properties, as long as all components of the path except the final property name are non-null. You can use compound or nested property names when you set bean properties, as long as all components of the path except the final property name are not null.

Continue

Working with Collection Element Props in Spring Application

With this example I will show you how to inject Collections type Props in Spring applications. This is similar to the element type Map I had shown in another example. I am going to use Spring Boot framework but I will show you both using application.properties file as well as traditional XML config file to configure the props elements. In order to show how Collections type Props can be injected in a Spring Bean I will create a simple Spring Bean with a property Properties.

Continue

Call Stored Procedure using Spring StoredProcedure

This tutorial will show you how we can call stored procedure using Spring StoredProcedure. I assume you have a basic idea on stored procedure what it does and what are the advantages of using stored procedure. I am going to build the project using both maven and gradle build tools. Related Posts: Call Stored Procedure using Spring SimpleJdbcCall Sometimes we need to call a stored procedure while a single SQL statement is unable to fulfil our requirements because, it permits to execute multiple SQL statements and it also allows us…

Continue

Call Stored Procedure using Spring SimpleJdbcCall

This tutorial will show you how you can call or execute stored procedure using Spring SimpleJdbcCall. SimpleJdbcCall API provides flexible methods to invoke stored procedure. You can use DataSource directly with SimpleJdbcCall or you can create JdbcTemplate using DataSource and use JdbcTemplate with SimpleJdbcCall API for calling the stored procedures. You can also use RowMapper or BeanProprtyMapper of type POJO class as a return type while executing stored procedures using Spring’s SimpleJdbcCall API. I am also going to use @Qualifier annotation for resolving ambiguity while using SimpleJdbcCall with DataSource and…

Continue

Injecting properties value in Spring

This tutorial will show you how we can auto inject value from properties file in Spring. For this tutorial we will create a standalone maven project in Eclipse. If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse. Prerequisites The following things are required in order to run the application Eclipse Helios JDK 1.6 Have maven installed and configured Spring dependencies in pom.xml Now we will see the…

Continue