当前位置: 首页 > wzjs >正文

wordpress 建站教程 下载广州一起做网站

wordpress 建站教程 下载,广州一起做网站,网站建设公司经营范围,ps做网站顶部如题。在实例化Bean时,会根据配置依次调用方法。在此测试代码如下: 在测试类中继承接口InitializingBean,接口InterfaceUserService(该接口为自定义,只是定义set方法)。 InterfaceUserService&#xff0c…

如题。在实例化Bean时,会根据配置依次调用方法。在此测试代码如下:

在测试类中继承接口InitializingBean,接口InterfaceUserService(该接口为自定义,只是定义set方法)。

InterfaceUserService,接口InterfaceUserDao不影响测试,

package com.itheima.service.interfaces;import com.itheima.dao.interfaces.InterfaceUserDao;/*** @copyright 2003-2024* @author    qiao wei* @date      2024-12-22* @version   1.0* @brief     * @history   name*            date*            brief*/
public interface InterfaceUserService {void show();void setUserDao001(InterfaceUserDao userDao);
}

测试类UserServiceImpl02

package com.itheima.service.impl;import org.springframework.beans.factory.InitializingBean;import com.itheima.dao.interfaces.InterfaceUserDao;
import com.itheima.service.interfaces.InterfaceUserService;/*** @copyright 2003-2024* @author    qiao wei* @date      2024-12-23* @version   1.0* @brief     有参构造方法。* @history   name*            date*            brief*/
public class UserServiceImpl02 implements InterfaceUserService, InitializingBean {public UserServiceImpl02() {System.out.println("类UserServiceImpl02调用无参构造函数。");}public UserServiceImpl02(InterfaceUserDao paramUserDao, double paramValue) {this.userDao = paramUserDao;this.value01 = paramValue;System.out.println("调用带参构造方法");
//        paramUserDao.print();
//        System.out.println("类UserServiceImpl02调用有参构造函数。---" + userDaoABC);
//        System.out.println(value01);}@Overridepublic void afterPropertiesSet() throws Exception {System.out.println("实现接口InitializingBean的方法afterPropertiesSet");}@Overridepublic void show() {System.out.println("类UserServiceImpl02的show方法。");System.out.println("打印字段数据。userDao:" + userDao + ",value01:" + value01);System.out.println(userDaoABC);}@Overridepublic void setUserDao001(InterfaceUserDao userDao) {System.out.println("调用属性设置方法。");this.userDaoABC = userDao;}private InterfaceUserDao userDao;private InterfaceUserDao userDaoABC;private double value01;
}

配置xml,配置构造方法的参数。

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><bean id="serviceImpl02"class="com.itheima.service.impl.UserServiceImpl02"><!--    构造方法参数    --><constructor-argname="paramUserDao"ref="userDao"></constructor-arg><constructor-argname="paramValue"value="100.0"></constructor-arg><!--    setUserDao001方法参数    --><property name="userDao001"ref="userDao"></property></bean><bean id="userDao"class="com.itheima.dao.impl.UserDaoImpl"></bean>
</beans>

Test类

package com.itheima.service.impl;import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.itheima.service.interfaces.InterfaceUserService;import static org.junit.jupiter.api.Assertions.*;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-02* @version   1.0* @brief     * @history   name*            date*            brief*/
class UserServiceImpl02Test {@Testpublic void test02() {ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("./xml/service/userServiceImpl02.xml");InterfaceUserService userService =(InterfaceUserService) applicationContext.getBean("serviceImpl02");
//        userService.show();}
}

运行结果如下:

在xml文件中没有配置init-method,如果配置了,应在方法afterPropertiesSet之后被调用。注意,因为在xml配置了构造方法的参数,所以在有无参、有参两个构造方法的情况下,调用了有参构造方法。

如果将xml文件中的构造方法参数注释掉,则运行结果自动调用无参构造方法。

注释掉的xml文件内容

运行结果:

所以在创建Bean'实例时,方法调用顺序如下:

构造方法

set***方法

接口InitializingBean的方法afterPropertiesSet。(如果继承接口 InitializingBean)。

xml配置的init-method方法。

 

http://www.dtcms.com/wzjs/802609.html

相关文章:

  • 网站建设淘宝类目做花茶网站解说
  • 企业网站开发开题报告盐城做网站推广电话
  • 江苏苏中建设集团股份有限公司网站网页制作教程 赵丰年
  • 汕头网站建设工作哪个网站可以做微信头图
  • 做公司门户网站怎么样进行网站建设
  • 卡片式网站模板建筑安装公司
  • 做网站协议书wordpress 首页
  • 翔安区建设局网站动易学校网站管理系统
  • 新民专业网站开发公司简洁大方的电商网站模板
  • 龙井建设局网站网站建设属于技术开发合同吗
  • 网站开发语言学习C 吗公司商城网站开发费做什么科目
  • 亚成成品网站源码南海佛山网站建设
  • 郑州网站建设与设计wordpress 亩
  • 网站注册实名制怎么做做网站找
  • 设计素材网站那个好wordpress如何添加表格
  • 深圳市公司网站建设企业俄语好网站设计
  • 惠民网站建设网站的流量检测怎么做
  • 搜索引擎网站优化和推广方案wordpress music pro
  • 优惠券网站怎么做的网页设计与制作怎么做清平调代码
  • 学校联网网站建设什么是网络建站
  • 电子商务网站建设花费网站商城建设
  • 企业网站经典案例人才市场招聘网站
  • 网站维护 案例环球设计网
  • 视频素材网站推荐建筑设计网上接单
  • 电子商务网站建设的一般曲靖模板网站建设
  • 网站设计实施陕西咸阳建设银行网站
  • 珠海网站建设公电商网站的建设背景
  • 装修公司谁做网站wordpress网站生成app应用
  • 设计师常用的图片网站wordpress主题二级菜单栏
  • 徐州沛县网站建设东莞工厂