First of all click on Project Explorer of eclipse and open the file context.xml
Read the rest of this entry »
Spring 3: Configuring data Source with tomcat
3 01 2012Comments : Leave a Comment »
Tags: tomcat
Categories : Application Server, Spring
Spring 3: Managing Transactions Programmatically without template
10 11 2011In this blog I’m going to show how to manage a transactional code with the simplest feature of spring.
First of all have a look to Spring 3: Implement CRUD pattern using hibernate session factory.
Now I’m going to build a simple interface to add a new Employee
package com.biancama.spring3.service.hibernate; import com.biancama.spring3.model.hibernate.Employees; public interface EmployeesService { public boolean addNewEmployee(Employees employee); }
Comments : Leave a Comment »
Categories : hibernate, Spring
Spring 3: Implement CRUD pattern using JPA Dao support
11 10 2011In this blog I’m going to implement spring jpa using eclipleLink.
First of all add the following snippet to your pom.xml
<dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.0.0</version> <scope>compile</scope> ... </dependency> </dependencies> ... <repositories> <repository> <id>EclipseLink Repo</id> <url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url> <!-- use this for javax.persistence <snapshots> <enabled>true</enabled> </snapshots> --> </repository> ...
Comments : Leave a Comment »
Categories : eclipselink, Spring
GWT & Spring 3: Integration using RPC (Part 3)
21 09 2011Let continue our example to integrate GWT with spring
Please visit the previous entry GWT & Spring 3: Integration using RPC (Part 1)
and GWT & Spring 3: Integration using RPC (Part 2)
To integrate the spring service with gwt service, we’re going to use gwt4spring it consists in a simple servlet.
To configure it add simple configuration lines in 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml, classpath:spring3-data-local.xml, classpath:spring3-data-hibernate.xml, classpath:spring-dozer.xml </param-value> </context-param> <servlet> <servlet-name>springGwtRemoteServiceServlet</servlet-name> <servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>springGwtRemoteServiceServlet</servlet-name> <url-pattern>/application/springGwtServices/*</url-pattern> </servlet-mapping> <!-- Default page to serve --> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
Comments : Leave a Comment »
Categories : GWT, Spring
Spring 3: Implement CRUD pattern using pure JPA
10 09 2011In this blog I’m going to implement spring jpa using eclipleLink.
First of all add the following snippet to your pom.xml
<dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.0.0</version> <scope>compile</scope> ... </dependency> </dependencies> ... <repositories> <repository> <id>EclipseLink Repo</id> <url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url> <!-- use this for javax.persistence <snapshots> <enabled>true</enabled> </snapshots> --> </repository> ...
Comments : Leave a Comment »
Categories : Spring
GWT & Spring 3: Integration using RPC (Part 2)
20 08 2011Let continue our example to integrate GWT with spring
Please visit the previous entry GWT & Spring 3: Integration using RPC (Part 1)
Now we’re going to create a service to get all employees, but before let create a converter to convert from domain object model to DTO model
package com.biancama.test.gwt.webapp.server.converter; import java.util.Collections; import java.util.Set; import org.dozer.DozerBeanMapper; import org.dozer.Mapper; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; public class DozerConverter implements GenericConverter, InitializingBean { /** Mapper Dozer */ private Mapper mapper; @Override public void afterPropertiesSet() throws Exception { if (mapper == null) { mapper = new DozerBeanMapper(); } } @Override public Set getConvertibleTypes() { return Collections.singleton(new ConvertiblePair(Object.class, Object.class)); } @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return mapper.map(source, targetType.getType()); } public void setMapper(Mapper mapper) { this.mapper = mapper; } }
Comments : Leave a Comment »
Categories : GWT, Spring
Spring 3: Implement CRUD pattern using hibernate ibatis Dao Support
9 08 2011Hello in this blog I’m going to implement a CRUD using Ibatis.
First of all I’m going to generate POJO and DAO classes using blog iBatis: Running myBatis generator with maven
After add a dependency in your pom.xml
file
<dependency> <groupId>org.apache.ibatis</groupId> <artifactId>ibatis-sqlmap</artifactId> <version>2.3.4.726</version> </dependency>
Comments : Leave a Comment »
Categories : Ibatis, Spring
GWT & Spring 3: Integration using RPC (Part 1)
20 07 2011In this blog I’m going to show a complete working example of integration between GWT(GXT) and spring .
First of all create a service class to retrieve all employees from database.
Our model business class of Employees is
package com.biancama.test.gwt.webapp.server.model; // Generated 23-feb-2011 14.26.58 by Hibernate Tools 3.4.0.CR1 import java.math.BigDecimal; import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.UniqueConstraint; /** * Employees generated by hbm2java */ @Entity @Table(name = "EMPLOYEES", uniqueConstraints = @UniqueConstraint(columnNames = "EMAIL")) public class Employees implements java.io.Serializable { private int employeeId; private Jobs jobs; private Departments departments; private Employees employees; private String firstName; private String lastName; private String email; private String phoneNumber; private Date hireDate; private BigDecimal salary; private BigDecimal commissionPct; private Set<Employees> employeeses = new HashSet<Employees>(0); private Set<Departments> departmentses = new HashSet<Departments>(0); private Set<JobHistory> jobHistories = new HashSet<JobHistory>(0); public Employees() { } public Employees(int employeeId, Jobs jobs, String lastName, String email, Date hireDate) { this.employeeId = employeeId; this.jobs = jobs; this.lastName = lastName; this.email = email; this.hireDate = hireDate; } public Employees(int employeeId, Jobs jobs, Departments departments, Employees employees, String firstName, String lastName, String email, String phoneNumber, Date hireDate, BigDecimal salary, BigDecimal commissionPct, Set<Employees> employeeses, Set<Departments> departmentses, Set<JobHistory> jobHistories) { this.employeeId = employeeId; this.jobs = jobs; this.departments = departments; this.employees = employees; this.firstName = firstName; this.lastName = lastName; this.email = email; this.phoneNumber = phoneNumber; this.hireDate = hireDate; this.salary = salary; this.commissionPct = commissionPct; this.employeeses = employeeses; this.departmentses = departmentses; this.jobHistories = jobHistories; } @Id @Column(name = "EMPLOYEE_ID", unique = true, nullable = false, precision = 6, scale = 0) public int getEmployeeId() { return this.employeeId; } public void setEmployeeId(int employeeId) { this.employeeId = employeeId; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "JOB_ID", nullable = false) public Jobs getJobs() { return this.jobs; } public void setJobs(Jobs jobs) { this.jobs = jobs; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "DEPARTMENT_ID") public Departments getDepartments() { return this.departments; } public void setDepartments(Departments departments) { this.departments = departments; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "MANAGER_ID") public Employees getEmployees() { return this.employees; } public void setEmployees(Employees employees) { this.employees = employees; } @Column(name = "FIRST_NAME", length = 20) public String getFirstName() { return this.firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } @Column(name = "LAST_NAME", nullable = false, length = 25) public String getLastName() { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; } @Column(name = "EMAIL", unique = true, nullable = false, length = 25) public String getEmail() { return this.email; } public void setEmail(String email) { this.email = email; } @Column(name = "PHONE_NUMBER", length = 20) public String getPhoneNumber() { return this.phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } @Temporal(TemporalType.DATE) @Column(name = "HIRE_DATE", nullable = false, length = 7) public Date getHireDate() { return this.hireDate; } public void setHireDate(Date hireDate) { this.hireDate = hireDate; } @Column(name = "SALARY", precision = 8) public BigDecimal getSalary() { return this.salary; } public void setSalary(BigDecimal salary) { this.salary = salary; } @Column(name = "COMMISSION_PCT", precision = 2) public BigDecimal getCommissionPct() { return this.commissionPct; } public void setCommissionPct(BigDecimal commissionPct) { this.commissionPct = commissionPct; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Employees> getEmployeeses() { return this.employeeses; } public void setEmployeeses(Set<Employees> employeeses) { this.employeeses = employeeses; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<Departments> getDepartmentses() { return this.departmentses; } public void setDepartmentses(Set<Departments> departmentses) { this.departmentses = departmentses; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "employees") public Set<JobHistory> getJobHistories() { return this.jobHistories; } public void setJobHistories(Set<JobHistory> jobHistories) { this.jobHistories = jobHistories; } }
Comments : Leave a Comment »
Categories : GWT, Spring
iBatis: Running myBatis generator with maven
10 07 2011In this blog I’m going to show how to integrate spring with myBatis and how to generate POJO classes and DAO classses from an existing data base.
First of all updation pom.xml
with myBatis support
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.biancama.test</groupId> <artifactId>spring3</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>spring3 Spring-WS Application</name> <url>http://www.springframework.org/spring-ws</url> <build> <finalName>spring3</finalName> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>${mybatis.generator.version}</version> <executions> <execution> <id>Generate MyBatis Artifacts</id> <!-- <goals> <goal>generate</goal> </goals> --> </execution> </executions> </plugin> </plugins> </build> <!-- Shared version number properties --> <properties> <org.springframework.version>3.0.5.RELEASE</org.springframework.version> <junit.version>4.8.2</junit.version> <slf4j.version>1.6.1</slf4j.version> <common-lang.version>2.5</common-lang.version> <hibernate.version>3.5.4-Final</hibernate.version> <hibernatetool.version>3.2.4.GA</hibernatetool.version> <hibernatevalidator.version>4.1.0.Final</hibernatevalidator.version> <com.oracle.version>11.2.0.1.0</com.oracle.version> <mybatis.version>3.0.4</mybatis.version> <mybatis.generator.version>1.3.1</mybatis.generator.version> <mybatis.generator.configurationFile>${basedir}/src/main/resources/generatorConfig.xml</mybatis.generator.configurationFile> <mybatis.generator.overwrite>true</mybatis.generator.overwrite> </properties> <repositories> <repository> <id>mybatis-snapshot</id> <name>MyBatis Snapshot Repository</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories> <dependencies> <!-- Core utilities used by other modules. Define this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Expression Language (depends on spring-core) Define this if you use Spring Expression APIs (org.springframework.expression.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define this if you use Spring Bean APIs (org.springframework.beans.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Aspect Oriented Programming (AOP) Framework (depends on spring-core, spring-beans) Define this if you use Spring AOP APIs (org.springframework.aop.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Application Context (depends on spring-core, spring-expression, spring-aop, spring-beans) This is the central artifact for Spring's Dependency Injection Container and is generally always defined --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Various Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration Define this if you need any of these integrations --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Transaction Management Abstraction (depends on spring-core, spring-beans, spring-aop, spring-context) Define this if you use Spring Transactions or DAO Exception Hierarchy (org.springframework.transaction.*/org.springframework.dao.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and iBatis. (depends on spring-core, spring-beans, spring-context, spring-tx) Define this if you need ORM (org.springframework.orm.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans. (depends on spring-core, spring-beans, spring-context) Define this if you need OXM (org.springframework.oxm.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Web application development utilities applicable to both Servlet and Portlet Environments (depends on spring-core, spring-beans, spring-context) Define this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Spring MVC for Servlet Environments (depends on spring-core, spring-beans, spring-context, spring-web) Define this if you use Spring MVC with a Servlet Container such as Apache Tomcat (org.springframework.web.servlet.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Spring MVC for Portlet Environments (depends on spring-core, spring-beans, spring-context, spring-web) Define this if you use Spring MVC with a Portlet Container (org.springframework.web.portlet.*) --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc-portlet</artifactId> <version>${org.springframework.version}</version> </dependency> <!-- Support for testing Spring applications with tools such as JUnit and TestNG This artifact is generally always defined with a 'test' scope for the integration testing framework and unit testing stubs --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${org.springframework.version}</version> <scope>test</scope> </dependency> <!-- JUnit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- slf --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- Common jakarta --> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>${common-lang.version}</version> </dependency> <!-- Hibernate --> <!-- JSR 303 with Hibernate Validator --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>${hibernate.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernate.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernatevalidator.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-tools</artifactId> <version>${hibernatetool.version}</version> <scope>compile</scope> </dependency> <!-- Oracle --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>${com.oracle.version}</version> </dependency> <!-- myBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> </dependencies> </project>
Comments : Leave a Comment »
Categories : Ibatis, Spring
Spring 3: Implement CRUD pattern using hibernate Template
11 06 2011Hello in this blog I’m going to implement a CRUD using hibernate. In particular I’m going to use DAO support.
Fist of all declare root interface
package com.biancama.spring3.dao; import java.io.Serializable; public interface CRUDAccess<K extends Serializable, E> { public K getKey(E entity); public E merge(E entity); public void persist(E entity); public void remove(E entity); public E findById(K id); }
Comments : Leave a Comment »
Categories : hibernate, Spring