Spring入門(使用spring框架創(chuàng)建對象):
1.導(dǎo)入Spring相關(guān)的包
junit? ? Spring-context? ? Mybatis? Mybatis-spring

2.配置文件(spring.xml) 文件中必須要有xsi官方命名空間
<bean id="接口名" class="實現(xiàn)類全限定名">
bean的子標(biāo)簽property標(biāo)簽(用來在類中注入屬性) property中的屬性:
name:屬性名? ? ?ref:引用對象? ? ?value:普通值 比如double long int string
例如: <bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl">
3. 在idea中使用 Spring框架
context = new ClassPathXmlApplicationContext("文件名")
context.getBean("bean中id值")? ?獲取接口對應(yīng)的實現(xiàn)類對象
因為在Service中用到dao的對象 所以在spring.xml中的bean標(biāo)簽要使用property標(biāo)簽注入
例如:?<bean id="accountService"class="com.itheima.service.impl.AccountServiceImpl">
? ? ? ? ? ? ? ? ?<property? name="accountDao"? ref="accountDao"/>?
? ? ? ? ? ?</bean>? ? 注入property快捷鍵 Alt+insert
注意: 1.?這樣注入必須要求在 Service類中要有accountDao的set方法
? ? ? ? ? ?2.?name="accountDao" 其中property標(biāo)簽name的屬性值要和類中set方法名一致
? ? ? ? ? ?3.??ref="accountDao"? ref引用
二. 構(gòu)造注入(使用構(gòu)造函數(shù))
格式: <constructor-arg name="字段名" value="賦值"></constructor-arg>
使用場景:使用此類時必須要帶有參數(shù) 不植入?yún)?shù)無法創(chuàng)建對象


三.其他各種注入
依次為: 數(shù)組array? list?集合?set集合? map集合? properties文件 注入

四.創(chuàng)建對象的方式
1.實例工廠方法創(chuàng)建


2.Spring factoryBean 標(biāo)準(zhǔn)化方式創(chuàng)建

