创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

今天就跟大家聊聊有关Spring框架中如何使用IOC实现装配Bean,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
IOC装配Bean
(1)Spring框架Bean实例化的方式提供了三种方式实例化Bean
下面先写这三种方法的applicationContext.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" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Bean的三种实例化方式=================== -->
<!-- 2.1 使用无参的构造器 -->
<bean id="bean1" class="com.study.spring.b_instance.Bean1"></bean>
<!-- 2.2使用静态工厂方法 factory-method 是工厂提供的静态方法 -->
<bean id="bean2" class="com.study.spring.b_instance.Bean2" factory-method="createInstance"></bean>
<!-- 2.3配置实例化工厂的方法 -->
<bean id="bean3Factory" class="com.study.spring.b_instance.Bean3Factory"></bean>
<bean id="bean3" factory-bean="bean3Factory" factory-method="getInstance"></bean>
<!-- end.Bean的三种实例化方式==================== -->