第一步:导入相关jar包(此范例导入的是spring3.2.4版本,spring2.5版本只需要导入spring核心包即可)

重新学习之spring第一个程序,配置IOC容器

 

 

第二步:在项目的src下配置applicationContext.xml的配置文件

applicationContext.xml文件

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4         xmlns:aop="http://www.springframework.org/schema/aop"
 5         xmlns:tx="http://www.springframework.org/schema/tx"
 6         xsi:schemaLocation="
 7             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 8             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
 9             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
10     
11     <!-- 
12         lazy-init:true 懒加载,初始ioc化容器的时候,不建立对象
13         lazy-init:false(默认) 不懒加载,初始化ioc容器的时候,就讲applicationContext.XML中所有配置的类的对象创建,并建立关系
14         scope:prototype每次取对应id的类的对象,都新创建一个
15         scope:singleton(默认)类似于单例模式,只要容器初始化一个类对象,以后所有的取用,都是取这一个
16       -->
17       
18       <!-- 通过setter方法,依赖注入对象。控制反转 -->
19     <bean id="userDao" class="com.bjsxt.shang.dao.UserDao" lazy-init="default" scope="singleton"></bean>
20     <bean id="userAction" class="com.bjsxt.shang.action.UserAcion" lazy-init="default" scope="prototype">
21         <property name="userDao" ref="userDao"></property>
22     </bean>
23     
24     
25     
26 </beans>
View Code

相关文章:

  • 2021-07-01
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-12-10
  • 2021-06-02
  • 2021-12-04
猜你喜欢
  • 2021-07-12
  • 2021-11-11
  • 2022-01-02
  • 2022-01-08
  • 2021-12-18
  • 2022-12-23
  • 2022-02-18
相关资源
相似解决方案