Spring的消息和事件實例
package cn
/** *//**
* @author hanwei
*
*/
public class User
private String name;
private int age;
public int getAge()
return age;
}
public void setAge(int age)
this
}
public String getName()
return name;
}
public void setName(String name)
this
}
}
userlogin user
自定義下雨的事件
package cn
import org
/** *//**
* @author hanwei
*
*/
public class RainEvent extends ApplicationEvent
public RainEvent(Object arg
super(arg
System
}
}
下雨事件監聽器
package cn
import org
import org
/** *//**
* @author hanwei
*
*/
public class RainListener implements ApplicationListener
/**//* (non
* @see org
org
*/
public void onApplicationEvent(ApplicationEvent arg
if(arg
System
}
}
}
配置文件
<!
<beans xmlns=
xmlns:xsi=
xsi:schemaLocation=
<bean id=
lazy
<property name=
<value>hanweivalue>
property>
<property name=
<value>
property>
bean>
<bean id=
class=
abstract=
dependency
<property name=
bean>
<bean id=
lazy
bean>
beans>
測試類
package cn
import java
import java
import org
import org
/** *//**
* @author hanwei
*
*/
public class MianTest
public static void main(String[] args)
ApplicationContext context = new ClassPathXmlApplicationContext(
User user = (User)context
Object[] obj=new Object[]
System
System
context
}
}
OK了
使用者 hanwei 於
user hanwei login at
烏雲密布
唐僧大喊
log
log
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28987.html