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"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	<context:component-scan base-package="com.atguigu.spring.beans.annotation"></context:component-scan>

</beans>

<?xml version="1.0" encoding="UTF-8"?>

-<beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans">

<!-- 1. 默认情况下, IOC 容器中的 bean 是单例的! 若对象是单例的, 则在创建 IOC 容器时即创建 bean 的实例, 并对 bean 的属性进行初始化.2. 可以通过 bean 的 scope 属性来修改 bean 的作用域. 若取值为 prototype, 则 bean 为原型的: 每次向容器获取实例, 得到的都是一个新的对象. 而且, 不在创建 IOC 容器时创建 bean 的实例了.3. IOC 容器中 bean 的生命周期:3.1 一般地, 讨论 bean 的生命周期, 是建立在 bean 是单例的基础上的.3.2 可以为 bean 指定 init 和 destroy 方法 3.3 还可以通过 bean 的后置处理器来更加丰富 bean 的生命周期方法(面试时.). -->



-<bean destroy-method="destroy" init-method="init" scope="singleton" class="com.atguigu.spring.helloworld.HelloWorld" id="helloWorld">

<property value="atguigu" name="userName"/>

</bean>

<!-- 1. 在 IOC 容器中配置 bean 之间的关联关系 -->


<bean class="com.atguigu.spring.ref.UserDao" id="userDao"/>


-<bean class="com.atguigu.spring.ref.UserService" id="userService">

<property name="userDao" ref="userDao"/>

</bean>


-<bean class="com.atguigu.spring.ref.UserAction" id="userAction">

<property name="userService" ref="userService"/>

</bean>

</beans>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值