<?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.xsd">
<bean id=" messageSource" class=" org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message</value>
<value>mess</value>
<value>messages</value>
</list>
</property>
<property name="defaultEncoding" value="utf-8"></property>
</bean>
<!-- <bean id="guojihua" class="com.zdc.Guojihua">
<constructor-arg name="name" value="大豪门" type="java.lang.String"></constructor-arg>
</bean> -->
<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.xsd">
<bean id=" messageSource" class=" org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message</value>
<value>mess</value>
<value>messages</value>
</list>
</property>
<property name="defaultEncoding" value="utf-8"></property>
</bean>
<!-- <bean id="guojihua" class="com.zdc.Guojihua">
<constructor-arg name="name" value="大豪门" type="java.lang.String"></constructor-arg>
</bean> -->
</beans>
1、bean 中加载的类是固定的,只需写入进去即可;
2、查看spring api可以发现
有setBasename(配置一个.properties文件)和setBasenames(配置多个.properties文件)。bean中property标签就是Java类中的set方法。所以该种配置是加载过个.properties文件。这三个.propertis文件表示三种类型。messs_en_US.propertis表示美国英语,在bean中配置可以省略_en_us只取mess作为值。message_zh_CN.properties表示中国汉语。messages.properties表示普通的.propertis文件。
调用方式:
途中占位符对应下图{0}