扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
package cn.xy.hw; /** *//** * @author hanwei * */ public class User ...{ private String name; private int age; public int getAge() ...{ return age; } public void setAge(int age) ...{ this.age = age; } public String getName() ...{ return name; } public void setName(String name) ...{ this.name = name; } } |
userlogin user ...{0} login at ...{1} |
package cn.xy.hw; import org.springframework.context.ApplicationEvent; /** *//** * @author hanwei * */ public class RainEvent extends ApplicationEvent ...{ public RainEvent(Object arg0) ...{ super(arg0); System.out.println("乌云密布、闪电、打雷,紧接着,下起了瓢泼大雨。"); } } |
package cn.xy.hw; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; /** *//** * @author hanwei * */ public class RainListener implements ApplicationListener ...{ /**//* (non-Javadoc) * @see org.springframework.context.ApplicationListener#onApplicationEvent( org.springframework.context.ApplicationEvent) */ public void onApplicationEvent(ApplicationEvent arg0) ...{ if(arg0 instanceof RainEvent)...{ System.out.println("唐僧大喊:"+arg0.getSource()+"赶快收衣服喽!"); } } } |
<!--sp-->xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="user" class="cn.xy.hw.User" abstract="false" lazy-init="default" autowire="default" dependency-check="default"> <property name="name"> <value>hanweivalue> property> <property name="age"> <value>20value> property> bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" abstract="false" lazy-init="default" autowire="default" dependency-check="default"> <property name="basename" value="xiyou">property> bean> <bean id="listener" class="cn.xy.hw.RainListener" abstract="false" lazy-init="default" autowire="default" dependency-check="default"> bean> beans> |
package cn.xy.hw; import java.util.Calendar; import java.util.Locale; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** *//** * @author hanwei * */ public class MianTest ...{ public static void main(String[] args) ...{ ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); User user = (User)context.getBean("user"); Object[] obj=new Object[]...{user.getName(),Calendar.getInstance().getTime()}; System.out.println(context.getMessage("userlogin",obj ,"找不到指定模块!",Locale.CHINA)); System.out.println(context.getMessage("userlogin",obj ,"找不到指定模块!",Locale.US)); context.publishEvent(new RainEvent("下雨了!")); } } |
使用者 hanwei 于 07-8-26 下午6:14登入 user hanwei login at 8/26/07 6:14 PM 乌云密布、闪电、打雷,紧接着,下起了瓢泼大雨。 唐僧大喊:下雨了!赶快收衣服喽! log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). log4j:WARN Please initialize the log4j system properly. |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者