1. 程式人生 > >Spring bean

Spring bean

ans 配置 spring配置 -i pro framework version Coding utf

1.Spring bean


1)編寫各個實體類
Java 各個類,描述對象

2)聲明spring的配置文件
<?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">
</beans>

3)在spring配置文件中,配置各個實體類(bean)
<beans ...>
<!-- 配置各個實體類,常用屬性 -->
<!-- bean的配置,id 在容器中的唯一標識;class 實體類的位置路徑;ref="" 容器中的bean 的引用,值為bean 的id; -->
<bean id="" class="">
<!-- bean 的屬性配置;配置實體類成員變量的值,name 是實體類的屬性名(成員變量),value 是屬性的值,ref 是對bean 的引用(與value互斥); -->
<property name="" value="" ref=""></property>
</bean>
</beans>

Spring bean