Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring and dependency injection

487 views

Published on

Dependency injection and Basic Introduction to Spring

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Spring and dependency injection

  1. 1. 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"; }}
  2. 2. package com.habuma.spring;public class HelloWorldBean{ public String sayHello(){ return"HelloWorld"; }}
  3. 3. package session.stateless;import javax.ejb.Stateless;import javax.ejb.LocalBean;@Stateless@LocalBeanpublic class ForDemo { public String sayHello() { return "HelloWorld"; }}
  4. 4. http://www.youtube.com/watch?v=CkjRvBMwzo4
  5. 5. 1. Spring Aspect-oriented programing(AOP) framework2. Boilerplate reduction through templates3. Spring Inverse Of Control (IOC) container
  6. 6. 1. Spring Aspect-oriented programing(AOP) framework2. Boilerplate reduction through templates3. Spring Inverse Of Control (IOC) container
  7. 7. public EmployeegetEmployeeById(longid){ return employee; Connectionconn=null; } catch(SQLExceptione){ PreparedStatementstmt=null; } finally{ ResultSetrs=null; if(rs!=null){ try { try { conn =dataSource.getConnection(); rs.close(); } catch(SQLExceptione){} stmt =conn.prepareStatement( } "select id,firstname,lastname,salaryfrom"+ if(stmt!=null){ "employee whereid=?"); try { stmt.setLong(1,id); stmt.close(); } catch(SQLExceptione){} rs =stmt.executeQuery(); } Employeeemployee=null; if(conn!=null){ try { if (rs.next()){ conn.close(); employee=newEmployee(); } catch(SQLExceptione){} employee.setId(rs.getLong("id")); } employee.setFirstName(rs.getString("firstname")); } employee.setLastName(rs.getString("lastname")); return null; employee.setSalary(rs.getBigDecimal("salary")); } }
  8. 8. 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);}
  9. 9. http://www.springsource.org/ - Homepage of Spring framework. Containsdocumentation of how to use Spring

×