A generic enterprise application framework/skeleton.
FEATURES OF THE FRAMEWORK
eaframework-frontend-war.war is used for presentation logic and it has following files
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>eaframework-common-jar</module>
<module>eaframework-backend-jar</module>
<module>eaframework-service-war</module>
<module>eaframework-frontend-war</module>
<module>eaframework-ear</module>
<module>eaframework-other-jar</module>
<module>eaframework-other-war</module>
<module>eaframework-other-ear</module>
</modules>
</project>
How i created maven ear structure?
- Spring 3.2.x - Annotations Based
- JPA with Hibernate, EclipseLink, Any ORM you can use/replace
- AOP - AspectJ
- JSR 303 - Validation Specification
- JUnit
- SLF4J with LOG4J, Any other logging framework you can use/replace
- Maven
- Bootstrap, JQuery, JSP, Spring-taglib-views
- Dozer Mapper
- Design Patterns
- Factory
- Facade
- MVC, VO, and Other
- MySQL
- Eclipse Luna
- JDK1.7
- Tomee,Any
- JavaDoc
- Package-By-Feature
- Naming conventions, project structure, package structure, files structure and locations, pom.xml structure and all
- Here I used separate JARs/WARs for separate logic/layers, for example
- eaframework-backend-jar.jar has persistence logic(DAO classes)
- eaframework-service-war.war has service/controller logic(Business classes, Controller classes)
- eaframework-common-jar.jar has common logic(DTO, other utility classes)
- eaframework-frontend-war.war has presentation logic(JSPs, Bootstrap, AngularJS, Whatever)
- eaframework-other-jar.jar has other logic in this separate jar if needed
- eaframework-other-war.war has other logic in this separate war if needed
- eaframework-other-ear.ear has other logic in this separate ear if needed
- eaframework-ear.ear is main ear which has all above application's JARs/WARs
- This EA structure provide re-usability
eaframework-frontend-war.war is used for presentation logic and it has following files
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>eaframework-frontend-war</display-name>
<welcome-file-list>
<welcome-file>/pages/enroll.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>eaframework-frontendContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>eaframework-frontendContext</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/eaframework-frontendContext-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
eaframework-frontendContext-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Common JAR Configuration -->
<import resource="classpath*:eaframework-commonContext.xml" />
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/static/**" location="/static/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/pages directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:properties/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
</beans>
enroll.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<spring:eval var="hostUrl" expression="@commonProperties.hostUrl"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Enrollment Form</title>
<link href="<c:url value='/static/css/bootstrap.css' />"
rel="stylesheet"></link>
<link href="<c:url value="/static/css/custom.css" />" rel="stylesheet"
type="text/css" />
</head>
<body>
<div class="form-container">
<h1>Employee Enrollment Form</h1>
<!-- modelAttribute="employee" -->
<form method="POST"
action="${hostUrl}/eaframework-service-war/registrationController/save.htm"
class="form-horizontal">
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="username">Username</label>
<div class="col-md-7">
<input type="text" name="username" id="username"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="username" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="password">Password</label>
<div class="col-md-7">
<input type="password" name="password" id="password"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="password" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="firstname">First
Name</label>
<div class="col-md-7">
<input type="text" name="firstname" id="firstname"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="firstname" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="lastname">Last
Name</label>
<div class="col-md-7">
<input type="text" name="lastname" id="lastname"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="lastname" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="sex">Gender</label>
<div class="col-md-7" class="form-control input-sm">
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female
<div class="has-error">
<form:errors path="sex" class="help-inline" />
</div>
</div>
</div>
</div>
<%-- <div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="dob">Date of
birth</label>
<div class="col-md-7">
<form:input type="text" path="dob" id="dob"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="dob" class="help-inline" />
</div>
</div>
</div>
</div> --%>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="email">Email</label>
<div class="col-md-7">
<input type="text" name="email" id="email"
class="form-control input-sm" />
<div class="has-error">
<form:errors path="email" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="qualification">Qualification</label>
<div class="col-md-7" class="form-control input-sm">
<input type="radio" name="qualification" value="Graduate" />Graduate
<input type="radio" name="qualification" value="Post Graduate" />Post
Graduate <input type="radio" name="qualification"
value="Doctorate" />Doctorate
<div class="has-error">
<form:errors path="qualification" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="country">Country</label>
<div class="col-md-7">
<select name="country" id="country" class="form-control input-sm">
<option value="">Select Country</option>
<option id="INDIA" value="INDIA">INDIA</option>
<option id="AUSTRALIA" value="AUSTRALIA">AUSTRALIA</option>
<option id="NEWZEALAND" value="NEW ZEALAND">NEW ZEALAND</option>
<option id="GERMANY" value="GERMANY">GERMANY</option>
<option id="ITALY" value="ITALY">ITALY</option>
<option id="OTHER" value="OTHER">OTHER</option>
</select>
<div class="has-error">
<form:errors path="country" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="firstAttempt">First
Attempt ?</label>
<div class="col-md-1">
<input type="checkbox" name="firstAttempt"
class="form-control input-sm">
<div class="has-error">
<form:errors path="firstAttempt" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="skills">Skills</label>
<div class="col-md-7">
<select name="skills" multiple size="5"
class="form-control input-sm">
<option value="Java">Java</option>
<option value="Shell Scripting">Shell Scripting</option>
<option value="Linux Admin">Linux Admin</option>
<option value="Windows Admin">Windows Admin</option>
<option value="QA">QA</option>
<option value="Testing">Testing</option>
</select>
<div class="has-error">
<form:errors path="skills" class="help-inline" />
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-actions floatRight">
<input type="submit" value="Register"
class="btn btn-primary btn-sm">
</div>
</div>
</form>
</div>
</body>
</html>
success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Enrollment Detail Confirmation</title>
<link href="<c:url value='/resources/css/custom.css' />" rel="stylesheet"></link>
</head>
<body>
<div class="success">
<%-- Congratulations! Mr.${employee.getUsername()} your detail ${yourmessage} are saved.. --%>
Hello! <%=request.getParameter("yourmessage") %> your detail are saved.. Congrats!!
</div>
</body>
</html>
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>eaframework-frontend-war</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>eaframework-frontend-war Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<properties>
<spring.version>3.2.14.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<servlet.version>3.0.1</servlet.version>
<jdk.version>1.7</jdk.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring TestContext Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JUnit testing dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Servlet dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- Hibernate library dependecy end -->
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-common-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>eaframework-frontend-war</finalName>
<plugins>
<!-- we want sources to be processed by a specific 1.7 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.google.eaframework</groupId>
</project>
eaframework-common-jar.jar is used for common logic and it get deployed in other JARs/WARs/EARs of the application. here it has following files.
eaframework-commonContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.google.eaframework.common.dto" />
<context:component-scan base-package="com.google.eaframework.common.util" />
<!-- It is used to inject property value inside JSP -->
<util:properties id="commonProperties"
location="classpath:properties/eaframework-common-default.properties" />
<!-- It is used to inject property value inside @Controller -->
<context:property-placeholder location="classpath:properties/eaframework-common-default.properties"/>
</beans>
eaframework-common-default.properties
###### URL MAPPING ######
hostUrl=http://localhost:8080
log4j.properties
# CONFIGURING LOG4J AS LOGGER IMPLEMENTATION
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\ealogfile.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=TRACE, stdout, file
# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO
# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL
EmployeeDTO.java
package com.google.eaframework.common.dto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Employee DTO object
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
public class EmployeeDTO implements Serializable {
/**
*
*/
private static final long serialVersionUID = -584011059917834216L;
private String username;
private String password;
private String firstname;
private String lastname;
private String gender;
private String email;
private String qualification;
private String country;
private boolean firstAttempt;
private List<String> skills = new ArrayList<String>();
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public boolean isFirstAttempt() {
return firstAttempt;
}
public void setFirstAttempt(boolean firstAttempt) {
this.firstAttempt = firstAttempt;
}
public List<String> getSkills() {
return skills;
}
public void setSkills(List<String> skills) {
this.skills = skills;
}
@Override
public String toString() {
return "Employee [username=" + username + ", password=" + password
+ ", firstname=" + firstname + ", lastname=" + lastname
+ ", gender=" + gender + ", email=" + email
+ ", qualification=" + qualification + ", country=" + country
+ ", firstAttempt=" + firstAttempt + ", skills=" + skills + "]";
}
}
LoggerUtility.java
package com.google.eaframework.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A Logger utility class
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
public class LoggerUtility {
/*
* Logger factory method. We are setting LOG4J(as Logger Implementation) properties in log4j.properties
*/
public static Logger getLogger(@SuppressWarnings("rawtypes") Class c)
{
Logger logger=LoggerFactory.getLogger(c);
/*
* The above line will automatically detect logging configuration from log4j.properties file but this file must be in root classpath
* AND if log4j.properties file is not on the classpath then we must use PropertyConfiguration.configure(....)
* Example code is something like this below which is not working currently
* PropertyConfigurator.configure("properties/log4j.properties");
*/
return logger;
}
}
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-common-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<name>eaframework-common-jar Maven JAR</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<properties>
<spring.version>3.2.14.RELEASE</spring.version>
<hibernate.version>3.2.3.GA</hibernate.version>
<hibernate-annotations.version>3.3.0.GA</hibernate-annotations.version>
<junit.version>4.12</junit.version>
<servlet.version>3.0.1</servlet.version>
<jdk.version>1.7</jdk.version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.validator.version>5.1.2.Final</hibernate.validator.version>
<javax.validation.version>1.1.0.Final</javax.validation.version>
<mysql-connector-java>5.1.9</mysql-connector-java>
<log4j.version>1.2.15</log4j.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring AOP + AspectJ -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<!-- Spring TestContext Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JUnit testing dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Servlet dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSR303 validation dependencies -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java}</version>
</dependency>
<!-- Hibernate 4.3.6 core library library -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- Hibernate 4.3.6 JPA support -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- Dependencies for Eclipse JPA Persistence API -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0-RC1</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Hibernate annotation -->
<!-- <dependency> <groupId>hibernate-annotations</groupId> <artifactId>hibernate-annotations</artifactId>
<version>${hibernate-annotations.version}</version> </dependency> <dependency>
<groupId>hibernate-commons-annotations</groupId> <artifactId>hibernate-commons-annotations</artifactId>
<version>3.0.0.GA</version> </dependency> -->
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- Hibernate library dependecy end -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId>
<version>6.0</version> <scope>provided</scope> </dependency> -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Dozer Mapper -->
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.4.0</version>
</dependency>
</dependencies>
<build>
<finalName>eaframework-common-jar</finalName>
<plugins>
<!-- we want sources to be processed by a specific 1.7 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
eaframework-service-war.war is used for service logic(service layer, restful controller layer) and it has following files.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>eaframework-service-war</display-name>
<servlet>
<servlet-name>eaframework-serviceContext</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>eaframework-serviceContext</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/eaframework-serviceContext-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
eaframework-serviceContext-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- Common JAR Configuration -->
<import resource="classpath*:eaframework-commonContext.xml" />
<!-- Backend JAR Configuration -->
<import resource="classpath*:eaframework-backendContext.xml" />
<!-- AOP AspectJ Configuration For EAFramework Service -->
<import resource="classpath*:/aspect/eaframework-service-aspect.xml" />
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Enabling annotation driven configuration /-->
<context:annotation-config/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:properties/messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<!-- Auto scan the components -->
<context:component-scan base-package="com.google.eaframework.service.registration" />
</beans>
RegistrationController.java
package com.google.eaframework.service.registration;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.google.eaframework.common.dto.EmployeeDTO;
/**
* A RESTful controller class for user registration
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@Controller
@RequestMapping("/")
public class RegistrationController {
private @Value("${hostUrl}") String hostUrl;
/*
* Injecting RegistrationService object.
*/
@Autowired
RegistrationService registrationService;
public void setRegistrationService(RegistrationService registrationService) {
this.registrationService = registrationService;
}
/**
* This method will be called on form submission, handling POST request
*
* @return success jsp on success
*/
@RequestMapping(value = "registrationController/save.htm", method = RequestMethod.POST)
public ModelAndView save(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("firstname") String firstname, @RequestParam("lastname") String lastname, @RequestParam("gender") String gender, @RequestParam("email") String email, @RequestParam("qualification") String qualification, @RequestParam("country") String country, @RequestParam(value="firstAttempt", required = false, defaultValue = "false") boolean firstAttempt, @RequestParam("skills") List<String> skills, ModelMap model) {
EmployeeDTO employeeDTO = new EmployeeDTO();
employeeDTO.setUsername(username);
employeeDTO.setPassword(password);
employeeDTO.setFirstname(firstname);
employeeDTO.setLastname(lastname);
employeeDTO.setGender(gender);
employeeDTO.setEmail(email);
employeeDTO.setQualification(qualification);
employeeDTO.setCountry(country);
employeeDTO.setFirstAttempt(firstAttempt);
employeeDTO.setSkills(skills);
registrationService.save(employeeDTO);
return new ModelAndView("redirect:"+hostUrl+"/eaframework-frontend-war/pages/success.jsp", "yourmessage", employeeDTO.getUsername());
}
}
RegistrationService.java
package com.google.eaframework.service.registration;
import com.google.eaframework.common.dto.EmployeeDTO;
/**
* A business interface for user registration
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
public interface RegistrationService {
/*
* The business method that will serve registration details to persistence object
*/
public void save(EmployeeDTO employeeDTO);
}
RegistrationServiceImpl.java
package com.google.eaframework.service.registration;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.eaframework.backend.dao.RegistrationDao;
import com.google.eaframework.backend.domain.EmployeeEntity;
import com.google.eaframework.common.dto.EmployeeDTO;
/**
* A business implementation class for user registration
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@Service("registrationService")
public class RegistrationServiceImpl implements RegistrationService {
/*
* Injecting RegistrationDao object.
*/
@Autowired(required = true)
RegistrationDao registrationDao;
public void setRegistrationDao(RegistrationDao registrationDao) {
this.registrationDao = registrationDao;
}
/**
* It serve registration details to persistence object
* @param it take Employee object as input
* @return nothing
*/
public void save(EmployeeDTO employeeDTO) {
Mapper mapper = new DozerBeanMapper();
EmployeeEntity employeeEntity = mapper.map(employeeDTO, EmployeeEntity.class);
registrationDao.save(employeeEntity);
}
}
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-service-war</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>eaframework-service-war Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<properties>
<spring.version>3.2.14.RELEASE</spring.version>
<hibernate.version>3.2.3.GA</hibernate.version>
<hibernate-annotations.version>3.3.0.GA</hibernate-annotations.version>
<junit.version>4.12</junit.version>
<servlet.version>3.0.1</servlet.version>
<jdk.version>1.7</jdk.version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.validator.version>5.1.2.Final</hibernate.validator.version>
<javax.validation.version>1.1.0.Final</javax.validation.version>
<mysql-connector-java>5.1.9</mysql-connector-java>
<log4j.version>1.2.15</log4j.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring AOP + AspectJ -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<!-- Spring TestContext Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JUnit testing dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Servlet dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSR303 validation dependencies -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java}</version>
</dependency>
<!-- Hibernate 4.3.6 core library library -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- Hibernate 4.3.6 JPA support -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- Dependencies for Eclipse JPA Persistence API -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0-RC1</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Hibernate annotation -->
<!-- <dependency> <groupId>hibernate-annotations</groupId> <artifactId>hibernate-annotations</artifactId>
<version>${hibernate-annotations.version}</version> </dependency> <dependency>
<groupId>hibernate-commons-annotations</groupId> <artifactId>hibernate-commons-annotations</artifactId>
<version>3.0.0.GA</version> </dependency> -->
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- Hibernate library dependecy end -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId>
<version>6.0</version> <scope>provided</scope> </dependency> -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Dozer Mapper -->
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-common-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-backend-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>eaframework-service-war</finalName>
<plugins>
<!-- we want sources to be processed by a specific 1.7 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- code will add dependency jars in MANIFEST.MF file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
eaframework-backend-jar.jar is used for persistence logic and it has following files
db.sql
-- CREATING A SCHEMA FOR ENTERPRISE APPLICATION
CREATE DATABASE `eadb` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */;
-- CREATING A ENTITY FOR SCHEMA OF ENTERPRISE APPLICATION
CREATE TABLE `employee` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`password` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`firstname` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`lastname` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`gender` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`email` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`qualification` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`country` varchar(50) COLLATE utf8_bin DEFAULT NULL,
`skills` varchar(50) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=119 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="EAFrameworkJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.google.eaframework.backend.domain.EmployeeEntity</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence>
eaframework-backendContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- Common JAR Configuration -->
<import resource="classpath*:eaframework-commonContext.xml" />
<!-- Unit Testing Configuration -->
<import resource="classpath*:/unittesting/eaframework-backend-unittesting.xml" />
<!-- AOP AspectJ Configuration For EAFramework Backend -->
<import resource="classpath*:/aspect/eaframework-backend-aspect.xml" />
<tx:annotation-driven />
<context:component-scan base-package="com.google.eaframework.backend.dao" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/eadb" />
<property name="username" value="root" />
<property name="password" value="mysql" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="EAFrameworkJPA" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
</beans>
eaframework-backend-aspect.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<aop:aspectj-autoproxy />
<!-- Aspect -->
<bean id="logAspect" class="com.google.eaframework.backend.aspect.LoggingAspect" />
</beans>
eaframework-backend-unittesting.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.google.eaframework.backend.registration.test" />
</beans>
RegistrationDao.java
package com.google.eaframework.backend.dao;
import com.google.eaframework.backend.domain.EmployeeEntity;
/**
* A persistence interface for user registration
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
public interface RegistrationDao {
/*
* This method will persist registration to db
*/
public void save(EmployeeEntity employeeEntity);
}
RegistrationDaoImpl.java
package com.google.eaframework.backend.dao;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.google.eaframework.backend.domain.EmployeeEntity;
/**
* A persistence implementation class for user registration
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@Repository("registrationDao")
public class RegistrationDaoImpl implements RegistrationDao {
@PersistenceContext
private EntityManager entityManager;
@Transactional
public void save(EmployeeEntity employeeEntity) {
entityManager.persist(employeeEntity);
}
}
EmployeeEntity.java
package com.google.eaframework.backend.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* A employee domain object(Entity) class
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@Entity
@Table(name = "employee")
public class EmployeeEntity{
/**
* variables of this entity
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="ID", nullable = false)
private int id;
@Column(name="username", nullable = false)
private String username;
@Column(name="password", nullable = false)
private String password;
@Column(name="firstname", nullable = false)
private String firstname;
@Column(name="lastname", nullable = false)
private String lastname;
@Column(name="gender", nullable = false)
private String gender;
@Column(name="email", nullable = false)
private String email;
@Column(name="qualification", nullable = false)
private String qualification;
@Column(name="country", nullable = false)
private String country;
@Column(name="skills", nullable = false)
private String skills;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getSkills() {
return skills;
}
public void setSkills(String skills) {
this.skills = skills;
}
}
RegistrationDaoTest.java
package com.google.eaframework.backend.registration.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
/**
* A TestCase for Registration DAO
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/resources/unittesting/eaframework-backend-unittesting.xml")
@TransactionConfiguration(defaultRollback = true)
//@Transactional
public class RegistrationDaoTest {
/*
* Initializing logger using logger factory method.
*/
@Test
public void testSave() {
assertEquals("saved", "saved");
}
}
LoggingAspect.java
package com.google.eaframework.backend.aspect;
import java.util.Arrays;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import com.google.eaframework.common.util.LoggerUtility;
/**
* A Logging Aspect (It uses AspectJ framework)
*
* @author: SIRAJ CHAUDHARY
* @version 6.1
* @since 6.0
*/
@Aspect
public class LoggingAspect {
/*
* Initialising logger using logger factory method.
*/
private static final Logger logger = LoggerUtility
.getLogger(LoggingAspect.class);
@Before("execution(* com.google.eaframework.backend.dao.RegistrationDaoImpl.save(..))")
public void logBefore(JoinPoint joinPoint) {
logger.info("********************");
logger.info("Executing " + joinPoint.getSignature().getName()
+ "() method of " + joinPoint.getTarget().getClass());
logger.info("********************");
}
@After("execution(* com.google.eaframework.backend.dao.RegistrationDaoImpl.save(..))")
public void logAfter(JoinPoint joinPoint) {
logger.info("********************");
logger.info("Finishing " + joinPoint.getSignature().getName()
+ "() method of " + joinPoint.getTarget().getClass());
logger.info("********************");
}
@AfterReturning(pointcut = "execution(* com.google.eaframework.backend.dao.RegistrationDaoImpl.save(..))", returning = "result")
public void logAfterReturning(JoinPoint joinPoint, Object result) {
logger.info(joinPoint.getSignature().getName()
+ "() method returned value is : " + result);
}
@AfterThrowing(pointcut = "execution(* com.google.eaframework.backend.dao.RegistrationDaoImpl.save(..))", throwing = "error")
public void logAfterThrowing(JoinPoint joinPoint, Throwable error) {
logger.info(joinPoint.getSignature().getName() + " throws the Exception : " + error);
}
//@Around("execution(* com.google.eaframework.backend.dao.RegistrationDaoImpl.save(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("logAround() is running!");
logger.info("hijacked method : " + joinPoint.getSignature().getName());
logger.info("hijacked arguments : "
+ Arrays.toString(joinPoint.getArgs()));
logger.info("Around before is running!");
joinPoint.proceed(); // continue on the intercepted method
logger.info("Around after is running!");
}
}
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-backend-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<name>backend</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.5.RELEASE</spring.version>
<hibernate.version>4.1.9.Final</hibernate.version>
<junit.version>4.12</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring TestContext Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- JUnit testing dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>transaction-api</artifactId>
<version>1.1-rev-1</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-common-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>eaframework-backend-jar</finalName>
<plugins>
<!-- we want sources to be processed by a specific 1.7 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
eaframework-ear.ear is main project's ear it has all above JARs/WARs/EARs
pom.xml
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>eaframework-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-common-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-backend-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-frontend-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.google.eaframework</groupId>
<artifactId>eaframework-service-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
eaframework-PARENT.pom is just like PARENT to all your projects(EARs/WARs/JARs). You don't deploy this on server and even you don't need to import this in eclipse while working with your ear, just import your particular ear and its appropriate WARs/JARs from this PARENT folder and start work.
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google</groupId>
<artifactId>eaframework-PARENT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>eaframework-common-jar</module>
<module>eaframework-backend-jar</module>
<module>eaframework-service-war</module>
<module>eaframework-frontend-war</module>
<module>eaframework-ear</module>
<module>eaframework-other-jar</module>
<module>eaframework-other-war</module>
<module>eaframework-other-ear</module>
</modules>
</project>
OUTPUT SCREENS
How i created maven ear structure?
Note: After doing much R&D, I couldn't find any maven archetype which give a good structure of ear such as it should generate standard directory layout and all. So now i followed my own approach to create a standard maven ear structure. How?
Step1: In eclipse first create a maven parent project(here packaging should be pom type and not ear/jar/other). It will be a parent project for all ear/war/jar/other.
Step2: Create WAR/JAR from command prompt and not from eclipse(so it will give you standard directory layouts). You can create these all inside the above parent project folder location. Than import those WAR/JAR in eclipse by first doing this.
mvn eclipse:eclipse -Dwtpversion=2.0 --> For WAR
(above line tells maven to convert the project into an eclipse WAR, not default JAR)
mvn eclipse:eclipse--> For JAR
Step3: Open pom.xml of parent project->overview tab->module(add all ear/war/jar which will treated as modules of the parent project)
Step4: Create EAR project now in eclipse.
Step5: Open pom.xml of EAR->tab(dependencies)->add dependencies(WAR/JAR) for this EAR.
Step6: Similarly create n-number of EAR(EAR inside EAR), WAR, JAR and add those inside the parent project
Please let me know if there is any maven archetype which will give me a standard ear project layout so i can skip this all doing manually.