bean 配置文件属性 init-method 用于在bean初始化时指定执行方法,用来替代继承 InitializingBean接口。相关链接:https://www.cnblogs.com/JoeyWong/p/9304737.html

测试程序如下:

public class TestInitMethod{
public void testInit(){
System.out.println("test init-method");
}
}

配置文件如下:

<bean id="testInitMethod" class="com.TestInitMethod" init-method="testInit"></bean>

Main主程序如下:

public class Main {
public static void main(String[] args){
ClassPathXmlApplicationContext context1 = new ClassPathXmlApplicationContext("spring.xml");
  }
}

打印如下结果:

test init-method

注意的一点是只有一个类完整的实例被创建出来后,才能走初始化方法。

Spring配置文件中指定init-method属性的作用的更多相关文章

  1. Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件

    1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...

  2. Spring 源码(4)在Spring配置文件中自定义标签如何实现?

    Spring 配置文件自定义标签的前置条件 在上一篇文章https://www.cnblogs.com/redwinter/p/16165274.html Spring BeanFactory的创建过 ...

  3. Spring配置文件中使用ref local与ref bean的区别

    Spring配置文件中使用ref local与ref bean的区别.在ApplicationResources.properties文件中,使用<ref bean>与<ref lo ...

  4. 通过java程序调用ant build.xml配置文件中指定的target

    一.概述 通过ant实现项目的自动化部署,jar包生成,替换,tomcat关停.启动,查看项目日志: 通过java程序调用已编辑好的ant脚本build.xml配置文件中指定的target: 文中文件 ...

  5. Spring配置文件中的parent与abstract

    在看项目的Spring配置文件时,发现消息队列的配置采用了继承方式配置Bean,在这梳理总结一下. 其实在基于spring框架开发的项目中,如果有多个bean都是一个类的实例,如配置多个数据源时,大部 ...

  6. 通过Spring配置文件中bean中的property赋值

    基本数据类型赋值-通过spring配置文件中bean中的property 扩展-以此方式可以通过配置为连接数据的属性赋值 1.如果是基本数据类型,可以通过setter方法为对象中的属性设置初始值,应用 ...

  7. 在spring配置文件中引入外部properties配置文件 context:property-placeholder

    在spring的配置文件中,有时我们需要注入很多属性值,这些属性全都写在spring的配置文件中的话,后期管理起来会非常麻烦.所以我们可以把某一类的属性抽取到一个外部配置文件中,使用时通用spring ...

  8. C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问

    摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...

  9. struts2配置文件中action的name属性

    struts2配置文件中action的name属性的第一个字符不要加斜杠 <action name="see" class="baoxiuManage_seeAct ...

随机推荐

  1. (7)JPA - Hibernate【从零开始学Spring Boot】

    在说具体如何在spring boot 使用Hibernate前,先抛装引玉些知识点?什么是JPA呢? JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象- ...

  2. 完整的html+css+javascript实现跟随鼠标移动显示选中效果

    1,显示效果: 2,html结构 <div class="process_list-lpu"> <div class="process_line&quo ...

  3. Storm同时接收多个源(spout和bolt)

    参考: http://blog.csdn.net/nyistzp/article/details/51483779

  4. NEFU 117

    可以用素数定理来解决. 素数定理:小于n的素数个数记为p(n),则随着n的增长,p(n)/(n/ln(n))=1. #include <iostream> #include <mat ...

  5. Linux内核project导论——网络:Netfilter概览

    简单介绍 最早的内核包过滤机制是ipfwadm.后来是ipchains.再后来就是iptables/netfilter了. 再往后,也就是如今是nftables. 只是nftables与iptable ...

  6. Zookeeper源代码编译为Eclipseproject(win7下Ant编译)

    为了深入学习ZooKeeper源代码,首先就想到将其导入到Eclispe中,所以要先将其编译为Eclispeproject. 1.什么是Ant??? Apache Ant™ Apache Ant is ...

  7. poj 3356

    Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...

  8. AWR系列之中的一个——AWR简单介绍

    AWR的全称是Automatic Workload Repository(自己主动负载知识库). 它是通过对照两次快照的方式收集到统计信息.来生成txt或者html页面形式的报告. 通常,通过AWR报 ...

  9. tensorflow利用预训练模型进行目标检测(一):安装tensorflow detection api

    一.tensorflow安装 首先系统中已经安装了两个版本的tensorflow,一个是通过keras安装的, 一个是按照官网教程https://www.tensorflow.org/install/ ...

  10. Linux下配置httpd服务

    第一步拷贝 cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd 第二步,修改 vim /etc/rc.d/init.d/httpd # ...