<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                org.springframework.beans.factory包提供了管理和控制bean的基本功能,包括使用編程的方式。org.springframework.context包的里面的ApplicationContext接口, 繼承了BeanFactory? 接口。 1.15.1 使用MessageSource國際化 String getMessage(String code, Object[] args, String default, Locale loc) String getMessage(String code, Object[] args, Locale loc) String getMessage(MessageSourceResolvable resolvable, Locale locale) Spring提供了兩種MessageSource?的實現, ResourceBundleMessageSource?和 StaticMessageSource 。 兩個都繼承自HierarchicalMessageSource?。 Resource 使用方式: <beans> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>format</value> <value>exceptions</value> <value>windows</value> </list> </property> </bean> </beans> 文件: # in format.properties m message=Alligators rock! # in exceptions.properties a argument.required=The {0} argument is required. public static void main(String[] args) { MessageSource resources = new ClassPathXmlApplicationContext("beans.xml"); String message = resources.getMessage("message", null, "Default", null); System.out.println(message); } } <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd"> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>com/oscar999/chp15/format</value> <value>exceptions</value> <value>windows</value> </list> </property> </bean> </beans> message=Hello, Oscar999! /** * @Title: MainTest.java * @Package com.oscar999.chp15 * @Description: TODO * @author oscar999 * @date Sep 3, 2018 2:32:09 PM * @version V1.0 */ package com.oscar999.chp15; import org.springframework.context.MessageSource; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @ClassName: MainTest * @Description: TODO * @author oscar999 */ public class MainTest { public static void main(String[] args) { MessageSource resources = new ClassPathXmlApplicationContext("com/oscar999/chp15/bean.xml"); String message = resources.getMessage("message", null, "Default", null); System.out.println(message); } } /** * @Title: Example.java * @Package com.oscar999.chp15 * @Description: TODO * @author oscar999 * @date Sep 3, 2018 2:44:07 PM * @version V1.0 */ package com.oscar999.chp15; import org.springframework.context.MessageSource; /** * @ClassName: Example * @Description: TODO * @author oscar999 */ public class Example { private MessageSource messages; public void setMessages(MessageSource messages) { this.messages = messages; } public void execute() { String message = this.messages.getMessage("argument.required", new Object[] { "userDao" }, "Required", null); System.out.println(message); } } <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd"> <!-- this MessageSource is being used in a web application --> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="com/oscar999/chp15/exceptions" /> </bean> <!-- lets inject the above MessageSource into this POJO --> <bean id="example" class="com.oscar999.chp15.Example"> <property name="messages" ref="messageSource" /> </bean> </beans> argument.required=The {0} argument is required. /** * @Title: MainTest.java * @Package com.oscar999.chp15 * @Description: TODO * @author oscar999 * @date Sep 3, 2018 2:32:09 PM * @version V1.0 */ package com.oscar999.chp15; import org.springframework.context.ApplicationContext; import org.springframework.context.MessageSource; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @ClassName: MainTest * @Description: TODO * @author oscar999 */ public class MainTest { public static void main(String[] args) { MessageSource resources = new ClassPathXmlApplicationContext("com/oscar999/chp15/bean.xml"); String message = resources.getMessage("message", null, "Default", null); System.out.println(message); ApplicationContext ctx = new ClassPathXmlApplicationContext("com/oscar999/chp15/bean1.xml"); Example example = (Example) ctx.getBean("example"); example.execute(); } } 國際化的話,建立如下文件: format_en_GB.properties,?exceptions_en_GB.properties, and?windows_en_GB.properties? 1.15.2 標準和客制事件 Spring提供了如下標準時間 -ContextRefreshedEvent -ContextStartedEvent -ContextStoppedEvent -ContextClosedEvent -RequestHandledEvent 客制事件 public class BlackListEvent extends ApplicationEvent { private final String address; private final String test; public BlackListEvent(Object source, String address, String test) { super(source); this.address = address; this.test = test; } // accessor and other methods... } } public class EmailService implements ApplicationEventPublisherAware { private List<String> blackList; private ApplicationEventPublisher publisher; public void setBlackList(List<String> blackList) { this.blackList = blackList; } public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { this.publisher = publisher; } public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } // send email... } } } 1.15.3 方便訪問低層級資源 使用Reousrce訪問。 1.15.4 方便的web程式ApplicationContext初始化 使用 ContextLoaderListener注冊應用上下文。 <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 這個監聽偵測contextConfigLocation參數, 如果不存在,則默認使用WEB-INF/applicationContext.xml。也可以使用路徑匹配的方式, 類似 WEB-INF/*Context.xml, WEB-INF/**/*Context.xml 1.15.5 作為Java EE RAR 文件的方式部署Spring ApplicationContext
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看