zoukankan      html  css  js  c++  java
  • 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">

  • 相关阅读:
    第11章 规模化微服务
    第10章 康威定律和系统设计
    9.3静态数据的安全
    第9章 安全
    第八章 监控
    7.8拯救消费者驱动的测试
    第7章 测试
    使用Spring + Jedis集成Redis
    activiti工作流数据库表详细介绍 (23张表)
    Redis是什么?Redis数据库全解?
  • 原文地址:https://www.cnblogs.com/swordyt/p/7047930.html
Copyright © 2011-2022 走看看