我們常常說用了Spring框架,但是spring框架到底有什麼作用呢?其實很多人都可以很輕出的告訴我,Spring使我們的開發更加簡單。那麼Spring是怎麼使我們的框架變得簡單的呢?
public class Helloworld implements SessionBean{
public void ejbActive(){
}
public void ejbRemove(){
}
public void ejbPassivae(){
}
public void setSessionContext(SessionContext ctx){
}
public String sayHello(){
return "你好!";
}
public void ejbCreate(){
}
}
public class Helloworld implements SessionBean{
public String sayHello(){
return "你好!";
}
}
public static void main(String[] args){
<span style="white-space:pre"> </span>/*加載Spring上下文*/
ApplicationContext context= new ClassPathXmlApplicationContext("applicationContext.xml");
<span style="white-space:pre"> </span>/*獲取TestAction bean*/
TestAction tx=(TestAction)ac.getBean("test.Action");
}
<bean id="auditorium"
class="com.springinaction.springidol.Auditorium"></bean>
<aop:config>
<!-- 確定切面爲auditorium類 -->
<aop:aspect ref="auditorium">
<!-- 切面方法爲:queryTest -->
<aop:pointcut id="queryTest"
expression="execution(* *.queryTest1())"/>
<!-- 橫切之前調用方法--turnOnLights -->
<aop:before pointcut-ref="queryTest"
method="turnOnLights"/>
<!-- 橫切之後調用方法--turnOffLights -->
<aop:after pointcut-ref="queryTest"
method="turnOffLights"/>
</aop:aspect>
</aop:config>
public Employee getEmployeebyID(long id){
return jdbcTemplate.queryForObject("select * from employee wher id=?",new RowMapper<Employee>(){
public Employee mapRow(ResultSet rs,int rowNum)throws SQLException{
Employee employee= new Employee();
employee.setId("12");
return employee;
}
},id);
}