Spring MVC Hibernate Tiles Project

Click here to download eclipse supported ZIP file



This is index.jsp JSP file and it is used display the output for the application.



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Spring3MVC with Hibernate3 CRUD Example using Annotations</title>
  </head>
  <body>
    <h2>Spring4 MVC with Hibernate4 CRUD Example using Annotations</h2>
    <h2>1. <a href="save">List of Employees</a></h2>
    <h2>2. <a href="add.html">Add Employee</a></h2>
  </body>
</html>


This is addEmployee.jsp JSP file and it is used display the output for the application.



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring MVC Form Handling</title>
</head>
<body>
<h2>Add Employee Data</h2>
<form:form method="POST" action="./save.html">
<fieldset>
    <table>
    <tr>
        <td><form:label path="empId">Employee ID:</form:label></td>
        <td><form:input path="empId" value="${employee.empId}" readonly="true"/></td>
    </tr>
    <tr>
        <td><form:label path="empName">Employee Name:</form:label></td>
        <td><form:input path="empName" value="${employee.empName}"/></td>
        <form:errors path="empName" cssClass="error"/>
    </tr>
    <tr>
        <td><form:label path="empAge">Employee Age:</form:label></td>
        <td><form:input path="empAge" value="${employee.empAge}"/></td>
    </tr>
    <tr>
        <td><form:label path="salary">Employee Salary:</form:label></td>
        <td><form:input path="salary" value="${employee.salary}"/></td>
    </tr>
    
    <tr>
        <td><form:label path="empAddress">Employee Address:</form:label></td>
                    <td><form:input path="empAddress" value="${employee.empAddress}"/></td>
                    <form:errors path="empAddress" cssClass="error"/>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" value="Submit"/></td>
      </tr>
</table> 
</fieldset>
</form:form>

  <c:if test="${!empty employees}">
<h2>List Employees</h2>
<table align="left" border="1">
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Age</th>
<th>Employee Salary</th>
<th>Employee Address</th>
<th>Actions on Row</th>
</tr>
<c:forEach items="${employees}" var="employee">
<tr>
<td><c:out value="${employee.empId}"/></td>
<td><c:out value="${employee.empName}"/></td>
<td><c:out value="${employee.empAge}"/></td>
<td><c:out value="${employee.salary}"/></td>
<td><c:out value="${employee.empAddress}"/></td>
<td align="center"><a href="edit.html?empId=${employee.empId}">Edit</a> | <a href="delete.html?empId=${employee.empId}">Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>


This is employeesList.jsp JSP file and it is used display the output for the application.



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>All Employees</title>
</head>
<body>
<h1>List Employees</h1>
<c:if test="${!empty employees}">
<table align="left" border="1">
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Age</th>
<th>Employee Salary</th>
<th>Employee Address</th>
</tr>
<c:forEach items="${employees}" var="employee">
<tr>
<td><c:out value="${employee.empId}"/></td>
<td><c:out value="${employee.empName}"/></td>
<td><c:out value="${employee.empAge}"/></td>
<td><c:out value="${employee.salary}"/></td>
<td><c:out value="${employee.empAddress}"/></td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>


This is footer.jsp JSP file and it is used display the output for the application.



<p>Copyright &copy; 2013 http://javacvtech.blogspot.in.com</p>


This is header.jsp JSP file and it is used display the output for the application.



<h2>Header- Employee Management System</h2>


This is mainTemplate.jsp JSP file and it is used display the output for the application.



<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
<tiles:insertAttribute name="title" ignore="true"></tiles:insertAttribute>
</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" align="left">
    <tr>
        <td colspan="2" align="center">
         <tiles:insertAttribute name="header"></tiles:insertAttribute>
        </td>
    </tr>
    <tr>
        <td>
         <tiles:insertAttribute name="menu"></tiles:insertAttribute>
        </td>
        <td>
         <tiles:insertAttribute name="body"></tiles:insertAttribute>
        </td>
    </tr>
    <tr>
        <td colspan="2"  align="center">
         <tiles:insertAttribute name="footer"></tiles:insertAttribute>
        </td>
    </tr>
</table>
</body>
</html>


This is menu.jsp JSP file and it is used display the output for the application.



<h2>Menu</h2>
 1. <a href="employees.html">List of Employees</a><br/>
 2. <a href="add.html">Add Employee</a>



This is EmployeeDao.java file having the DAO logic to access the database information.


 

    
package com.cv.spring.mvc.hibernate.dao;

import java.util.List;

import com.cv.spring.mvc.hibernate.model.Employee;

/**
 @author Chandra Vardhan
 *
 */
public interface EmployeeDao {
  
  public void addEmployee(Employee employee);

  public List<Employee> listEmployeess();
  
  public Employee getEmployee(Long empid);
  
  public void deleteEmployee(Employee employee);
}


This is EmployeeDaoImpl.java file having the DAO logic to access the database information.


 

    
package com.cv.spring.mvc.hibernate.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.cv.spring.mvc.hibernate.model.Employee;

/**
 @author Chandra Vardhan
 *
 */
@Repository("employeeDao")
public class EmployeeDaoImpl implements EmployeeDao {

  @Autowired
  private SessionFactory sessionFactory;
  
  public void addEmployee(Employee employee) {
    Session ses = sessionFactory.openSession();
    Transaction tx = ses.beginTransaction();    
    ses.save(employee);
    tx.commit();
  }

  
  public List<Employee> listEmployeess() {
    return (List<Employee>sessionFactory.openSession().createCriteria(Employee.class).list();
  }

  public Employee getEmployee(Long empid) {
    return (EmployeesessionFactory.openSession().get(Employee.class, empid);
  }

  public void deleteEmployee(Employee employee) {
    sessionFactory.openSession().createQuery("DELETE FROM Employee WHERE empid = "+employee.getEmpId()).executeUpdate();
  }

}


This is EmployeeController.java file having the controller logic and it will have the services defined in it.


 

    
package com.cv.spring.mvc.hibernate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cv.spring.mvc.hibernate.model.Employee;
import com.cv.spring.mvc.hibernate.model.EmployeeBean;
import com.cv.spring.mvc.hibernate.service.EmployeeService;

/**
 @author Chandra Vardhan
 *
 */
@Controller
public class EmployeeController {

  @Autowired
  private EmployeeService employeeService;

  @RequestMapping(value = "/save", method = RequestMethod.POST)
  public ModelAndView saveEmployee(@ModelAttribute("command"EmployeeBean employeeBean,
      BindingResult result) {
    if (result.hasErrors()) {
      return new ModelAndView("redirect:/index.html");
    }
    Employee employee = prepareModel(employeeBean);
    employeeService.addEmployee(employee);
    return new ModelAndView("redirect:/add.html");
  }

  @RequestMapping(value = "/employees", method = RequestMethod.GET)
  public ModelAndView listEmployees() {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("employees",
        prepareListofBean(employeeService.listEmployeess()));
    return new ModelAndView("employeesList", model);
  }

  @RequestMapping(value = "/add", method = RequestMethod.GET)
  public ModelAndView addEmployee(
      @ModelAttribute("command"EmployeeBean employeeBean,
      BindingResult result) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("employees",
        prepareListofBean(employeeService.listEmployeess()));
    if (result.hasErrors()) {
      return new ModelAndView("redirect:/index.html");
    }
    return new ModelAndView("addEmployee", model);
  }

  @RequestMapping(value = "/index", method = RequestMethod.GET)
  public ModelAndView welcome() {
    return new ModelAndView("redirect:/add.html");
  }

  @RequestMapping(value = "/delete", method = RequestMethod.GET)
  public ModelAndView editEmployee(
      @ModelAttribute("command"EmployeeBean employeeBean,
      BindingResult result) {
    employeeService.deleteEmployee(prepareModel(employeeBean));
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("employee"null);
    model.put("employees",
        prepareListofBean(employeeService.listEmployeess()));
    return new ModelAndView("addEmployee", model);
  }

  @RequestMapping(value = "/edit", method = RequestMethod.GET)
  public ModelAndView deleteEmployee(
      @ModelAttribute("command"EmployeeBean employeeBean,
      BindingResult result) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("employee", prepareEmployeeBean(employeeService
        .getEmployee(employeeBean.getEmpId())));
    model.put("employees",
        prepareListofBean(employeeService.listEmployeess()));
    return new ModelAndView("addEmployee", model);
  }

  private Employee prepareModel(EmployeeBean employeeBean) {
    Employee employee = new Employee();
    employee.setEmpAddress(employeeBean.getEmpAddress());
    employee.setEmpAge(employeeBean.getEmpAge());
    employee.setEmpName(employeeBean.getEmpName());
    employee.setSalary(employeeBean.getSalary());
    employee.setEmpId(employeeBean.getEmpId());
    // employeeBean.setId(null);
    return employee;
  }

  private List<EmployeeBean> prepareListofBean(List<Employee> employees) {
    List<EmployeeBean> beans = null;
    if (employees != null && !employees.isEmpty()) {
      beans = new ArrayList<EmployeeBean>();
      EmployeeBean bean = null;
      for (Employee employee : employees) {
        bean = new EmployeeBean();
        bean.setEmpName(employee.getEmpName());
        bean.setEmpId(employee.getEmpId());
        bean.setEmpAddress(employee.getEmpAddress());
        bean.setSalary(employee.getSalary());
        bean.setEmpAge(employee.getEmpAge());
        beans.add(bean);
      }
    }
    return beans;
  }

  private EmployeeBean prepareEmployeeBean(Employee employee) {
    EmployeeBean bean = new EmployeeBean();
    bean.setEmpAddress(employee.getEmpAddress());
    bean.setEmpAge(employee.getEmpAge());
    bean.setEmpName(employee.getEmpName());
    bean.setSalary(employee.getSalary());
    bean.setEmpId(employee.getEmpId());
    return bean;
  }
}


This is Employee.java file having the source code to execute business logic.


 

    
package com.cv.spring.mvc.hibernate.model;

import java.io.Serializable;

/**
 @author Chandra Vardhan
 *
 */
public class Employee implements Serializable{

  
  private Long empId;
  
  private String empName;
  
  private String empAddress;
  
  private Long salary;
  
  private Long empAge;

  public Long getEmpId() {
    return empId;
  }

  public void setEmpId(Long empId) {
    this.empId = empId;
  }

  public String getEmpName() {
    return empName;
  }

  public void setEmpName(String empName) {
    this.empName = empName;
  }

  public String getEmpAddress() {
    return empAddress;
  }

  public void setEmpAddress(String empAddress) {
    this.empAddress = empAddress;
  }

  public Long getSalary() {
    return salary;
  }

  public void setSalary(Long salary) {
    this.salary = salary;
  }

  public Long getEmpAge() {
    return empAge;
  }

  public void setEmpAge(Long empAge) {
    this.empAge = empAge;
  }

}


This is EmployeeBean.java file having the source code to execute business logic.


 

    
package com.cv.spring.mvc.hibernate.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 @author Chandra Vardhan
 *
 */
@Entity
@Table(name="Employee")
public class EmployeeBean implements Serializable{

  
  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  @Column(name = "empid")
  private Long empId;
  
  @Column(name="empname")
//  @Size(min = 3, max = 20, message = "Employee name must be between 3 and 20 characters Long.")
  private String empName;
  
  @Column(name="empaddress")
  private String empAddress;
  
  @Column(name="salary")
  private Long salary;
  
  @Column(name="empAge")
  private Long empAge;

  public Long getEmpId() {
    return empId;
  }

  public void setEmpId(Long empId) {
    this.empId = empId;
  }

  public String getEmpName() {
    return empName;
  }

  public void setEmpName(String empName) {
    this.empName = empName;
  }

  public String getEmpAddress() {
    return empAddress;
  }

  public void setEmpAddress(String empAddress) {
    this.empAddress = empAddress;
  }

  public Long getSalary() {
    return salary;
  }

  public void setSalary(Long salary) {
    this.salary = salary;
  }

  public Long getEmpAge() {
    return empAge;
  }

  public void setEmpAge(Long empAge) {
    this.empAge = empAge;
  }

}


This is EmployeeService.java file having the service/business logic to call the DAO layer and get the information from database.


 

    
package com.cv.spring.mvc.hibernate.service;

import java.util.List;

import com.cv.spring.mvc.hibernate.model.Employee;

/**
 @author Chandra Vardhan
 *
 */
public interface EmployeeService {
  
  public void addEmployee(Employee employee);

  public List<Employee> listEmployeess();
  
  public Employee getEmployee(Long empid);
  
  public void deleteEmployee(Employee employee);
}


This is EmployeeServiceImpl.java file having the service/business logic to call the DAO layer and get the information from database.


 

    
package com.cv.spring.mvc.hibernate.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cv.spring.mvc.hibernate.dao.EmployeeDao;
import com.cv.spring.mvc.hibernate.model.Employee;

/**
 @author Chandra Vardhan
 *
 */
@Service("employeeService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EmployeeServiceImpl implements EmployeeService {

  @Autowired
  private EmployeeDao employeeDao;
  
  public void addEmployee(Employee employee) {
    employeeDao.addEmployee(employee);
  }
  
  public List<Employee> listEmployeess() {
    return employeeDao.listEmployeess();
  }

  public Employee getEmployee(Long empid) {
    return employeeDao.getEmployee(empid);
  }
  
  public void deleteEmployee(Employee employee) {
    employeeDao.deleteEmployee(employee);
  }

}




This is pom.xml file having the entries of dependency jars and information to build the application .


	
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">.0" encoding="UTF-8"?> <modelVersion>4.0.0</modelVersion> <groupId>com.cv.spring.mvc.hibernate</groupId> <artifactId>SpringMVCHibernateTiles</artifactId> <name>SpringMVCHibernateTiles</name> <packaging>war</packaging> <version>1.0</version> <properties> <java-version>1.8</java-version> <org.springframework-version>4.2.0.RELEASE</org.springframework-version> <org.aspectj-version>1.6.10</org.aspectj-version> <org.slf4j-version>1.6.6</org.slf4j-version> <tiles.version>2.2.0</tiles.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${org.springframework-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.5.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>4.3.5.Final</version> </dependency> <dependency> <artifactId>hibernate-core</artifactId> <groupId>org.hibernate</groupId> <version>4.3.5.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.2.0.Final</version> </dependency> <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>4.0.4.Final</version> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.1.Final</version> </dependency> <dependency> <groupId>org.jboss.logging</groupId> <artifactId>jboss-logging</artifactId> <version>3.1.0.CR2</version> </dependency> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${org.aspectj-version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> provided </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> provided </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> test </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-api</artifactId> <version>${tiles.version}</version> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-core</artifactId> <version>${tiles.version}</version> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-jsp</artifactId> <version>${tiles.version}</version> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-servlet</artifactId> <version>${tiles.version}</version> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-template</artifactId> <version>${tiles.version}</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <warSourceDirectory>src/main/webapp</warSourceDirectory> <warName>SpringMVCHibernateTiles</warName> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </pluginManagement> <finalName>SpringMVCHibernateTiles</finalName> </build> </project>


This is employee.hbm.xml file having the spring configuration properties.


 
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.cv.spring.mvc.hibernate.model.Employee" table="Employee_new22">
<id name="empId" column="empId" type="java.lang.Long">
<generator class="identity" />
</id>
<property name="empName" column="empName" type="java.lang.String" />
<property name="empAddress" column="empAddress" type="java.lang.String" />
<property name="salary" column="salary" type="java.lang.Long" />
<property name="empAge" column="empAge" type="java.lang.Long" />
</class>
</hibernate-mapping>


This is sdnext-servlet.xml file having the spring configuration properties.


 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath:database.properties" />
<context:component-scan base-package="com.cv.spring.mvc.hibernate" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>
<!-- <bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean> -->

<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/config/tiles.xml</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.jdbc.factory_class">${hibernate.jdbc.factory_class}</prop>
</props>
</property>

</bean>
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- <bean class="org.springframework.context.support.ResourceBundleMessageSource"
id="messageSource">
</bean> -->

</beans>


This is tiles.xml file having the spring configuration properties.


 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/views/mainTemplate.jsp">
<put-attribute name="title" value=""></put-attribute>
<put-attribute name="header" value="/WEB-INF/views/header.jsp"></put-attribute>
<put-attribute name="menu" value="/WEB-INF/views/menu.jsp"></put-attribute>
<put-attribute name="body" value=""></put-attribute>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"></put-attribute>
</definition>

<definition name="addEmployee" extends="base.definition">
<put-attribute name="title" value="Employee Data Form"></put-attribute>
<put-attribute name="body" value="/WEB-INF/views/addEmployee.jsp"></put-attribute>
</definition>

<definition name="employeesList" extends="base.definition">
<put-attribute name="title" value="Employees List"></put-attribute>
<put-attribute name="body" value="/WEB-INF/views/employeesList.jsp"></put-attribute>
</definition>

</tiles-definitions>



This is web.xml deployment descriptor file and it describes how the web application should be deployed.


	
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/sdnext-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>sdnext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/sdnext-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sdnext</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>



This is log4j.properties file having the entries for logging the information into the console/file.



#By default enabling Console appender
# Root logger option
log4j.rootLogger=INFO, stdout

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%c]:%L -->> %m%n

# Redirect log messages to a log file
#log4j.appender.file=org.apache.log4j.RollingFileAppender
#log4j.appender.file.File=C:\servlet-application.log
#log4j.appender.file.MaxFileSize=5MB
#log4j.appender.file.MaxBackupIndex=10
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


No comments:

Post a Comment