• Spring《七》ApplicationContext


    1、国际化支持

    getMessage()提供了国际化支持。

    Bean中必须定义为messageSource。

    <bean id="messageSource" class="org.springfarmework.comtext.support.ResourceBundleMessage-Source">

    <property name="basename"> //固定

      <value>messages</value>//message.properties或者message.calss 国际化信息被定义在这样的文件中

    </property>

    </bean>

    内容

    HelloWorld=问候语:{0} 问候时间:{1}//0、1代表从外部传入的信息

    解决编码问题:

    native2ascii messages.properties messages.txt

    2、资源访问

    getResource()提供了资源获取支持。

    路径指定classpath(项目根目录)、file(全路径)或http、相对路径

    classpath:messages.properties

    file:d:/eclipse/messages.properties

    "WEB-INF/src/messages.properties"

    使用代码:

    ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");

    Resource resource=actx.getResource("classpath:messages.properties");

    3、事件传递

    ApplicationEvent:定义自定义的事件。

    ApplicationListener :用于接收事件。

    ApplicationContextAware:用于将自定义事件传递给事件通道。

    实现该接口主要是获取到applicationContext 句柄,该句柄提供了插入事件的方法。

    具体代码:

    LogEvent event=new LogEvent(log);

    this.applicationContext.publishEvent(event);

    配置文档config.xml中增加bean

    <bean id="listener" class="com.gc.action.LogListener">

  • 相关阅读:
    MySQL(DQL部分)
    Java函数式接口
    Java简易版生产者消费者模型
    浅谈Java三种实现线程同步的方法
    Linux常用命令
    计算机组成原理笔记
    资煌麻辣烫——事后诸葛亮
    资煌麻辣烫——冲刺集合
    资煌麻辣烫——测试总结
    资煌麻辣烫——冲刺总结
  • 原文地址:https://www.cnblogs.com/swordyt/p/7047930.html
Copyright © 2020-2023  润新知