28

Spring and dependency injection

Embed Size (px)

DESCRIPTION

Dependency injection and Basic Introduction to Spring

Citation preview

Page 1: Spring and dependency injection
Page 2: Spring and dependency injection
Page 3: Spring and dependency injection
Page 4: Spring and dependency injection
Page 5: Spring and dependency injection
Page 6: Spring and dependency injection
Page 7: Spring and dependency injection
Page 8: Spring and dependency injection
Page 9: Spring and dependency injection
Page 10: Spring and dependency injection
Page 11: Spring and dependency injection

package com.habuma.ejb.session; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class HelloWorldBean implements SessionBean{ public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} public void setSessionContext(SessionContextctx){} public void ejbCreate(){} public String sayHello(){ return"HelloWorld"; } }

Page 12: Spring and dependency injection

package com.habuma.spring; public class HelloWorldBean{ public String sayHello(){ return"HelloWorld"; } }

Page 13: Spring and dependency injection

package session.stateless; import javax.ejb.Stateless; import javax.ejb.LocalBean; @Stateless @LocalBean public class ForDemo { public String sayHello() { return "HelloWorld"; } }

Page 14: Spring and dependency injection

http://www.youtube.com/watch?v=CkjRvBMwzo4

Page 15: Spring and dependency injection

1. Spring Aspect-oriented programing(AOP) framework

2. Boilerplate reduction through templates

3. Spring Inverse Of Control (IOC) container

Page 16: Spring and dependency injection

1. Spring Aspect-oriented programing(AOP) framework

2. Boilerplate reduction through templates

3. Spring Inverse Of Control (IOC) container

Page 17: Spring and dependency injection
Page 18: Spring and dependency injection

public EmployeegetEmployeeById(longid){ Connectionconn=null; PreparedStatementstmt=null; ResultSetrs=null; try {

conn =dataSource.getConnection();

stmt =conn.prepareStatement( "select id,firstname,lastname,salaryfrom"+ "employee whereid=?"); stmt.setLong(1,id);

rs =stmt.executeQuery(); Employeeemployee=null;

if (rs.next()){

employee=newEmployee(); employee.setId(rs.getLong("id")); employee.setFirstName(rs.getString("firstname")); employee.setLastName(rs.getString("lastname")); employee.setSalary(rs.getBigDecimal("salary"));

}

return employee;

} catch(SQLExceptione){ } finally{

if(rs!=null){ try {

rs.close(); } catch(SQLExceptione){}

} if(stmt!=null){

try { stmt.close();

} catch(SQLExceptione){} } if(conn!=null){

try { conn.close();

} catch(SQLExceptione){} }

} return null;

}

Page 19: Spring and dependency injection

public EmployeegetEmployeeById(longid) {

return jdbcTemplate.queryForObject( "select id,firstname,lastname,salary"+ "from employeewhereid=?",

new RowMapper<Employee>(){

public EmployeemapRow(ResultSetrs, int rowNum)throwsSQLException{

Employee employee=newEmployee(); employee.setId(rs.getLong("id")); employee.setFirstName(rs.getString("firstname")); employee.setLastName(rs.getString("lastname")); employee.setSalary(rs.getBigDecimal("salary")); return employee;

} }

,id); }

Page 20: Spring and dependency injection
Page 21: Spring and dependency injection
Page 22: Spring and dependency injection
Page 23: Spring and dependency injection
Page 24: Spring and dependency injection

http://www.springsource.org/ - Home page of Spring framework. Contains documentation of how to use Spring

Page 25: Spring and dependency injection
Page 26: Spring and dependency injection
Page 27: Spring and dependency injection
Page 28: Spring and dependency injection