Tag Archives: Spring MVC

Sending Email with Spring MVC Using Template

This tutorial provides a sample spring MVC application that allows user sending an e-mail message. In this tutorial, you are supposed to familiar with Java EE development as well as developing Spring MVC-based applications. Spring Framework’s Support for E-mail Based on JavaMail, Spring framework provides high-level abstraction API which greatly simplifies e-mail sending process. Let’s take a brief look at this API in the following class diagram: To send e-mail messages, we can use an implementation of interface MailSender – the JavaMailSenderImpl class which is built upon on JavaMail. It’s convenient to configure this implementation as a bean in Spring’s context: Dependencies(pom.xml) The Mail Template File Name: verifyEmail.vm File Location: classpath: /mails/verifyEmail.vm (You can change this in configuration file) The…

Continue Reading

Spring AOP Example Using Annotation

Spring Framework is developed on two core concepts – Dependency Injection and Aspect Oriented Programming (AOP). Today we will look into the core concepts of Aspect Oriented Programming and how we can implement it using Spring Framework. Aspect Oriented Programming Overview Most of the enterprise applications have some common crosscutting concerns that is applicable for different types of Objects and modules. Some of the common crosscutting concerns are logging, transaction management, data validation etc. In Object Oriented Programming, modularity of application is achieved by Classes whereas in Aspect Oriented Programming application modularity is achieved by Aspects and they are configured to cut across different classes. AOP takes out the direct dependency of crosscutting tasks from classes that we can’t achieve…

Continue Reading

Integrate Spring MVC with Log4j

It’s quite straightforward to integrate Log4j into the Spring MVC application. First, include Log4j.jar library into your project dependency, then create a log4.properties file to define the Log4j’s appender and put this file into the project class path, Done. In tutorial, we show you how to integrate the Log4j 1.x logging framework into the Spring MVC application. Add Log4j Library to Your Project Download the Log4j library from the official website, or via Maven : Create log4j.properties Create a Log4j properties file (log4j.properties), put it into the project class path. see figure : File : log4j.properties – Define how log4j handling the logged message, in this example, it will redirect all the logged messages into a text. Use Log4j in…

Continue Reading

Unit Testing of Spring MVC Controllers

After all the services, DAO’s and support classes are tested then it’s time for the controller. Generally this is hard to test and most developers (based on observation) would rather just test it via Selenium or worse, by hand. That can work but it makes testing logic branches difficult and not to mention it’s time consuming. Plus no active developer would be willing to wait for browser tests to run before checking in code. Luckily the Spring MVC Test project can do full controller testing via unit tests, it was such a success that it’s now in Spring MVC core as of version 4.0.5. Getting Ready We can get the required testing dependencies by adding the following dependency declarations to…

Continue Reading

Spring 4 MVC Hello World Tutorial Using Maven

In this tutorial you will learn how to develop a Spring 4 MVC Hello world example. We hope this tutorial will give you a quick start with Spring MVC development using the latest Spring 4 Release. Technologies used: Spring 4.0.4.RELEASE JDK 1.8 Tomcat 7.0.53 Maven 3.2.1 Eclipse Java EE IDE ( Eclipse Kepler) Maven Project Setup In Eclipse Let us start with the creation of  a Maven web project in Eclipse. A maven web project archetype will create all the necessary folder structures required for a web project. We assume that you have installed the maven plugins for Eclipse. File -> New -> Other -> Maven -> Maven Project Click Next and Click Next again ( If you wish to…

Continue Reading
Contact Us
  • Room 614, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at] gmail.com