spring第一天
阿新 • • 發佈:2018-05-23
一個 關鍵字 enc 文件 技術分享 nco spring schema frame
Spring是一個基於IOC和AOP的結構J2EE系統的框架
IOC 反轉控制 是Spring的基礎,Inversion Of Control
簡單說就是創建對象由以前的程序員自己new 構造方法來調用,變成了交由Spring創建對象
DI 依賴註入 Dependency Inject. 簡單地說就是拿到的對象的屬性,已經被註入好相關值了,直接使用即可。
在src目錄下新建applicationContext.xml文件
applicationContext.xml是Spring的核心配置文件,通過關鍵字c即可獲取Category對象,該對象獲取的時候,即被註入了字符串"category 1“到name屬性中
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.how2java.pojo.Category"> <property name="name" value="category 1" /> </bean> </beans>
spring第一天