12 Sep

Spring Boot MVC with Tiles and AJAX

In my previous tutorials I have shown how to create a Spring Boot MVC application, here I will show you how to create an AJAX based Spring Boot MVC application with Tiles.

What is Tiles (https://tiles.apache.org/)

A free open-sourced templating framework for modern Java applications.
Based upon the Composite pattern it is built to simplify the development of user interfaces.

For complex web sites it remains the easiest and most elegant way to work alongside any MVC technology.

In summary, tiles allows authors to define page fragments which can be assembled into a complete pages at runtime. These fragments, or tiles, can be used as simple includes in order to reduce the duplication of common page elements or embedded within other tiles to develop a series of reusable templates. These templates streamline the development of a consistent look and feel across an entire application.

Read More

11 Aug

Spring Boot MVC with Maven

The primary motivation behind developing Spring Boot is to simplify the process for configuring and deploying the spring applications. Spring Boot will get rid of all the fuss involved on configuring the dependencies for building the enterprise applications. In Spring based applications, configurations are loaded with a bunch of XML files, now these configurations should not be maintained in a separate file which is extra work for the developers. Developers need to focus on only writing the application while Spring Boot will simplify the deployment process by packaging and deploying application without any explicit configurations.

You may also read Spring Boot MVC with Tiles and AJAX and http://www.jeejava.com/spring-mvc-and-jdbc-crud-with-zero-xml/

More information can be found here http://projects.spring.io/spring-boot/

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features

Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated ‘starter’ POMs to simplify your Maven configuration
Automatically configure Spring whenever possible
Provide production-ready features such as metrics, health checks and externalized configuration
Absolutely no code generation and no requirement for XML configuration

The reference guide includes detailed descriptions of all the features http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/.

Read More

09 Aug

Spring MVC and JDBC CRUD with zero XML

In my other tutorials Spring MVC and Spring JDBC ExampleSpring MVC and JDBC CRUD Example  I have used XML configurations but in this tutorial I have used only Annotation, so it means it uses zero XML configurations. This example shows how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also find how JDBC works with Spring MVC. We will also see how annotation like @Autowired works in Spring. You will also see how DispatcherServlet, DataSource and ViewResolver are configured in Spring using only Annotation. This example also shows how to integrate Spring 4 with Maven 3.

You may also read http://www.jeejava.com/spring-boot-mvc-with-maven/

For this tutorial we will create maven based web 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 configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven 3 installed and configured
Spring 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Read More

15 Jul

Spring MVC and JDBC CRUD Example

This tutorial shows an example on how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also find how JDBC works with Spring MVC. We will also see how annotation like @Autowired works in Spring. You will also see how datasource is configured in Spring. This example shows how to integrate Spring 4 with Maven 3. You may also read Spring MVC and Spring JDBC Example

Spring MVC and JDBC CRUD with zero XML

For this tutorial we will create maven based web 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 configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven 3 installed and configured
Spring 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Read More

28 Jan

Spring NamedParameterJdbcTemplate and Collections.singletonMap Example

In this post I will show you how to use NamedParameterJdbcTemplate and Collections.singletonMap to execute query. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (‘?’) arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTemplate to do much of its work. An SqlParameterSource is a source of named parameter values to a NamedParameterJdbcTemplate. The Collections.singletonMap returns an immutable map, mapping only the specified key to the specified value. The returned map is serializable.

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. Read More

27 Jan

Spring NamedParameterJdbcTemplate and BeanPropertySqlParameterSource Example

In this post I will show you how to use NamedParameterJdbcTemplate and BeanPropertySqlParameterSource to execute query. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (‘?’) arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTemplate to do much of its work. An SqlParameterSource is a source of named parameter values to a NamedParameterJdbcTemplate. The BeanPropertySqlParameterSource class is an implementation of SqlParameterSource interface. This class wraps an arbitrary JavaBean (that is, an instance of a class that adheres to the JavaBean conventions), and uses the properties of the wrapped JavaBean as the source of named parameter values.

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. Read More

26 Jan

Spring NamedParameterJdbcTemplate and MapSqlParameterSource Example

In this post I will show you how to use NamedParameterJdbcTemplate and MapSqlParameterSource to execute query. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (‘?’) arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTemplate to do much of its work. An SqlParameterSource is a source of named parameter values to a NamedParameterJdbcTemplate. The MapSqlParameterSource class is an implementation of SqlParameterSource interface. The MapSqlParameterSource class is a very simple implementation that is simply an adapter around a java.util.Map, where the keys are the parameter names and the values are the parameter values.

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. Read More

24 Jan

Get auto-generated id in Spring JDBC using SimpleJdbcInsert

In this post I will show you how to get auto generated id of a newly inserted row in table. Spring provides an easy way to get this auto-generated key using executeAndReturnKey method of SimpleJdbcInsert which is supported Spring JDBC 3 onwards.

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. Read More

23 Jan

Get auto-generated id in Spring JDBC using PreparedStatement

In this post I will show you how to get auto generated id of a newly inserted row in table. Spring provides an easy way to get this auto-generated key using KeyHolder which is supported Spring JDBC 3 onwards.

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 configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Have maven installed and configured
Spring and MySQL dependencies in pom.xml

Now we will see the below steps how to create a maven based spring project in Eclipse Read More

23 Sep

Spring @PostConstruct and @PreDestroy Example

This tutorial will show you how we can use @PostConstruct and @PreDestroy in Spring. @PostConstruct and @PreDestroy annotations are generally considered best practice for receiving lifecycle callbacks in a modern Spring application. Using these annotations means that our beans are not coupled to Spring specific interfaces. For more information please refer to http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-postconstruct-and-predestroy-annotations

Sometimes we need to load some data or perform initialization work after all necessary properties on the bean have been set by the container. In this example we will load data from database during application startup and set that value to a System property so that the value will be set only once and that value can be used later after retrieving from the System property. Read More

Share