|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在下面的代码中我只在java的main函数中调用了bean为customer名的bean为什么spring可以自动转换为date类型的变量在main函数中输出???????
main函数:
- ackage com.yiibai.common;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class App {
- public static void main(String[] args) {
- ApplicationContext context = new ClassPathXmlApplicationContext(
- "SpringBeans.xml");
- Customer cust = (Customer) context.getBean("customer");
- System.out.println(cust);
-
- }
- }
复制代码
对应的xml文件的配置:
- <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.5.xsd">
- <bean id="dateEditor"
- class="org.springframework.beans.propertyeditors.CustomDateEditor">
- <constructor-arg>
- <bean class="java.text.SimpleDateFormat">
- <constructor-arg value="yyyy-MM-dd" />
- </bean>
- </constructor-arg>
- <constructor-arg value="true" />
- </bean>
- <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
- <property name="customEditors">
- <map>
- <entry key="java.util.Date">
- <ref local="dateEditor" />
- </entry>
- </map>
- </property>
- </bean>
- <bean id="customer" class="com.yiibai.common.Customer">
- <property name="date" value="2015-12-31" />
- </bean>
- </beans>
复制代码 |
|