Spring @ConditionalOnProperty Example

Condition On Property Here I will create examples on Spring conditional on property using the annotation @ConditionalOnProperty. The @ConditionalOnProperty annotation allows you to load beans conditionally depending on a certain environment property or configuration of a property. Use the prefix and name attributes to specify the property that should be checked. By default, any property that exists and is not equal…

Spring @ConditionalOnClass and @ConditionalOnMissingClass

Conditional Class Spring @ConditionalOnClass and @ConditionalOnMissingClass annotations let @Configuration classes be included based on the presence or absence of specific classes. So @ConditionalOnClass loads a bean only if a certain class is on the class path and @ConditionalOnMissingClass loads a bean only if a certain class is not on the class path. This mechanism does not apply the same way…

Spring @ConditionalOnMissingBean Example

Conditional On Missing Bean In this tutorial I will create examples on Spring @ConditionalOnMissingBean. Anywhere you define a Spring bean, you can optionally add a condition. Only if the specified condition is satisfied then only bean will be added to the application context. To declare a condition, you can use any of the @Conditional… annotations. The @ConditionalOnMissingBean annotation lets a…

Spring @ConditionalOnBean Example

Conditional On Bean I will create examples on Spring @ConditionalOnBean. Anywhere you define a Spring bean, you can optionally add a condition. Only if the specified condition is satisfied then only bean will be added to the application context. To declare a condition, you can use any of the @Conditional… annotations. The @ConditionalOnBean annotation let a bean be included based…

Spring Boot – QueryForObject, QueryForList, BeanPropertyRowMapper

QueryForObject, QueryForList, BeanPropertyRowMapper In this post you will see how to select records using queryForObject(), queryForList(), BeanPropertyRowMapper in Spring Boot JdbcTemplate. Spring’s queryForObject() is used to fetch single row from the database. Spring’s queryForList() and BeanPropertyRowMapper are used to fetch multiple rows from the database. So, I will fetch single and multiple rows from the database using Spring JdbcTemplate.

How to Create Annotation based Spring Application

Introduction We will see how to create annotation based Spring application or annotation based configuration in Spring application. We will use here H2 database to perform database activities using Spring JDBC Template. We will not use any XML configuration here or zero XML configuration. We will also see how to run this stand-alone Spring application using main method. This application…

Integrate H2 In-memory Database with Spring

Introduction This tutorial will show you how to integrate in-memory H2 database with Spring. We will see here simple example to understand how it works. Here we will use Spring JDBC API to perform database activities. You can use this example with Spring based applications, such as, Spring Core, Spring MVC etc. You may also like to read Integrate H2…

Spring Data JPA CRUD Example

Introduction In this tutorial I will show you an example on Spring Data JPA CRUD. Here I will use the embedded or in-memory HSQL database. CRUD means Create, Read, Update, Delete. So I am going to perform basic CRUD operations on some entities. In this example I will create annotation based Spring standalone application. Related Posts: Embedded HSQL Database in…

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…

JSF 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate JSF 2, Spring 4, Hibernate 4 and Maven. In the previous example Spring 3, JSF 2 and Hibernate 3 integration example , I have shown how to integrate JSF 2, Spring 3 and Hibernate 3 but I have not used maven there. For this tutorial we will create maven based…