Home » Enterprise Java » spring » Page 27

spring

Update records in database with JdbcTemplate

In this example we shall show you how to update records in a database using the JdbcTemplate Class provided by the Spring Framework. The JdbcTemplate class is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract ...

Read More »

Select records from database with JdbcTemplate

With this example we are going to demonstrate how to select records from a database using the JdbcTemplate class provided by the Spring Framework. The JdbcTemplate class is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and ...

Read More »

Insert record in database with JdbcTemplate

This is an example of how to insert a record to the database using the JdbcTemplate class provided by the Spring Framework. The JdbcTemplate class is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. ...

Read More »

Sending e-mails with Spring

We will create a simple Spring service that will be used for sending mail. One method will create a SimpleMailMessage on the spot, while the other will use a preconfigured default message. The source code for the service is the following: package com.javacodegeeks.spring.mail; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; import org.springframework.stereotype.Service; @Service("mailService") public class MailService { @Autowired private MailSender mailSender; ...

Read More »

Declare bean in Spring container

With this example we are going to demonstrate how to declare a Bean in the Spring container. A Spring bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. In short, to declare a Class as a simple Spring Bean you should follow the steps below: 1. Include the following JARs in the classpath: ...

Read More »

Use preferences in Spring

Spring provides PreferencesPlaceholderConfigurer that can be used to load preferences. <bean id="preferencePlaceHolder" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="userTreePath" value="com.myapp.preference.staticPreferenceLoader" /> </bean> <bean id="myEntity" class="info.dependencyInjection.spring.factory.MyEntity"> <property name="value" value="${fruit}" /> </bean> Related Article: Use java.util.prefs.Preferences instead of java.util.Properties Reference: Use java.util.prefs.Preferences instead of java.util.Properties from our JCG partner Rahul Sharma at the “The road so far…” blog

Read More »

Spring MVC interceptor example

The demonstration code shows you how to modify the incoming HttpServletRequest object before it reaches your controller. This does nothing more than add a simple string to the request. public class RequestInitializeInterceptor extends HandlerInterceptorAdapter { // Obtain a suitable logger. private static Log logger = LogFactory .getLog(RequestInitializeInterceptor.class); /** * In this case intercept the request BEFORE it reaches the controller ...

Read More »