Spring使用xml配置,想要创建对象时注入想要的日期的方法

Spring使用xml配置,想要创建对象时注入想要的日期方法:

<!-- Spring使用xml配置,想要创建时注入想要的日期方法:-->
<bean id="accountService" class="org.zy.service.impl.AccountServiceImpl">
    <constructor-arg name="name" value="test"></constructor-arg>
    <constructor-arg name="age" value="1"></constructor-arg>
    <constructor-arg name="birthday" ref="now"></constructor-arg>
</bean>
<!-- 配置一个日期对象 -->
<bean id="now" factory-bean="now1" factory-method="parse">
    <constructor-arg name="source" value="2001-1-1 22:11:11"></constructor-arg>
</bean>
<bean id="now1" class="java.text.SimpleDateFormat" >
    <constructor-arg name="pattern" value="yyyy-MM-dd HH:mm:ss"></constructor-arg>
</bean>
package org.zy.service.impl;

import org.zy.service.IAccountService;

import java.util.Date;

/**
 * 
 */
public class AccountServiceImpl implements IAccountService {
    private String name;
    private Integer age;
    private Date birthday;

    public AccountServiceImpl(String name, Integer age, Date birthday){
        this.name = name;
        this.age = age;
        this.birthday = birthday;

    }
    public void saveAccount(){
        System.out.println("调用了..." + name + "," + age + "," + birthday);
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Spring.xmlSpring框架中的配置文件,用于配置和管理应用程序中的各种组件和依赖关系。它是基于XML格式的,并且是Spring框架的核心配置文件之一。 在Spring.xml中,可以定义以下内容: 1. Bean定义:通过定义Bean,可以告诉Spring框架如何创建和管理对象。每个Bean都有一个唯一的ID和一个类的全限定名。可以通过配置构造函数参数、属性注入、依赖关系等来配置Bean。 2. 依赖注入:通过配置依赖注入,可以让Spring框架自动管理对象之间的依赖关系。可以使用构造函数注入、Setter方法注入或字段注入来实现依赖注入。 3. 切面配置:通过配置切面,可以实现面向切面编程(AOP)的功能。可以定义切点、通知和切面,并将它们应用到指定的目标对象上。 4. 属性配置:可以在Spring.xml配置一些属性,如数据库连接信息、日志级别等。这些属性可以在应用程序中通过Spring框架进行读取和使用。 5. 声明式事务管理:可以通过配置声明式事务管理,来实现对数据库事务的管理。可以指定事务传播行为、隔离级别等属性。 6. 其他配置:还可以在Spring.xml配置其他一些内容,如国际化资源、拦截器、视图解析器等。 总的来说,Spring.xml配置文件是一个非常重要的文件,用于定义和配置应用程序中的各种组件和功能。通过合理配置Spring.xml,可以实现对应用程序的灵活管理和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@zhouyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值