<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<!--控制bean加载顺序 当一个bean想让另一bean在它之前加载可以设置depends-on 注意是加载顺序 -->
<!-- <bean class="bobo.User" id="user" depends-on="wife"/>-->
<!-- <bean class="bobo.Wife" id="wife"/>-->
<!---->
<!--懒加载
就不会在spring容器加载的时候 加载该bean
而是在使用的时候才会加载该bean -->
<!-- <bean class="bobo.Wife" lazy-init="true"/>-->
<!--作用域scope
singleton 默认值 同一个id始终只会创建一次bean
prototype 多例(原型) 每一次使用都会创建一个bean -->
<!-- <bean class="bobo.Person" id="person3" scope="prototype"/>-->
<!-- 使用静态工厂方式实例化bean-->
<!-- <bean class="bobo.Person" id="person3" factory-method="createPersonFacotry"/>-->
<!-- 使用实例工厂方法实例化-->
<!-- <bean class="bobo.PersonFacotry" id="personFacotry"/>-->
<!-- <bean class="bobo.Person" id="person4"-->
<!-- factory-bean="personFacotry"-->
<!-- factory-method="createPersonFactory"-->
<!-- ></bean>-->
<!-- 自动注入
byType 根据类型去自动匹配 当出现多个类型或者匹配到类型则会报错
byName 根据set方法的名字去自动匹配
constructor 根据构造器去匹配
优先会根据参数名字去匹配,假如参数名字没有匹配到,会根据参数类型去匹配
会根据构造函数的参数进行完整的匹配注入: 如果构造函数的参数Person(Wife wife3,User user) ioc容器里面必须要有同时有wife和user
名字没有匹配到会根据类型匹配 类型假如出现多个会注入失败但是不会报错
当根据类型匹配到多个 可以使用 1.设置某个bean为主要bean primary="true"
2.设置不需要自动注入的bean autowire-candidate="false" 忽略自动注入
-->
<bean class="bobo.Person" id="person3" autowire="byName"/>
<bean class="bobo.Wife" id="wife3" autowire-candidate="false"/>
<!--配置第三方bean -->
<bean class="com.alibaba.druid.pool.DruidDataSource" id="dataSource">
<property name="username" value="${mysql.username}"></property>
<property name="password" value="${mysql.password}"></property>
<property name="url" value="${mysql.url}"></property>
<property name="driverClassName" value="${mysql.driverClassName}"></property>
</bean>
</beans>
每日学习记录,如有错误,感谢指出!
