package cn.edu.tju.service;
public class BeerService {
public void defaultInit(){
System.out.println("default init method......");
}
public void myInitMethod(){
System.out.println("my init method......");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
default-init-method="defaultInit">
<bean id="beerService" class="cn.edu.tju.service.BeerService" init-method="myInitMethod"/>
</beans>
package cn.edu.tju.service;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestInit {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
context.getBean("beerService");
}
}
输出:文章来源地址https://www.toymoban.com/news/detail-671882.html
文章来源:https://www.toymoban.com/news/detail-671882.html
到了这里,关于Spring6.0官方文档示例:(26)配置文件中beans配置的default-init-method优先级低于bean上配置的init-method的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!