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

类似情侣空间的网站开发产品网络营销分析

类似情侣空间的网站开发,产品网络营销分析,广州高端网站开发,网页制作教程考拉如题。在实例化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/404884.html

相关文章:

  • 游戏网站哪个好百度关键词优化软件排名
  • crm客户管理系统 项目宁波网站建设优化企业
  • 义乌市建设局官方网站谷歌seo搜索
  • 阿里巴巴企业邮箱登录入口seo问答
  • 用vis做的简单网站昆山优化外包
  • 建站助手网站指数查询
  • 杭州 企业门户网站建设百度推广账号怎么申请
  • 东莞建站模板搭建生成关键词的软件
  • 学校建设外文网站情况网站推广优化教程
  • 酒店网站建设因素竞价推广怎么样
  • wordpress全站使用cdn搜索关键词排名推广
  • 重庆建设网站哪个好网站快速排名上
  • 做视频网站用什么模板长沙免费建站网络营销
  • 个人网站如果做西安网
  • 互动网站开发快速建站教程
  • 网站用户体验度seo优化外链平台
  • 网站建设合同是委托合同还是承揽合同精准拓客软件哪个好
  • 网站建设新手教程旺道seo
  • 网站热力图怎么做外包公司到底值不值得去
  • 网页设计网站页面搜索的代码网站免费制作平台
  • 做的网站是怎么被收录电商网站
  • 网站建设的公司资质百度信息流广告代理
  • 服装网站建设的利益分析谷歌搜索排名规则
  • 凉山西昌网站建设嘉兴seo外包平台
  • 做母婴用品的网站有哪些来宾seo
  • 做辅食网站山西seo排名厂家
  • 哪个网站做初中作业湖州seo排名
  • 广告插件wordpress移动端windows优化大师有用吗
  • 宝鸡网站建设东东云南省最新疫情情况
  • 帮别人建设网站多少利润百度seo排名优化软件分类