- prototype
- singleton
- session
- request
beans.xml的配置如下:
<?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-2.5.xsd"> <bean id="userService" class="com.jt.service.UserService" scope="prototype"> </bean> </beans>
1、prototype表示原始类型,也就是我们最开始使用的java对象声明方式,会生成多个对象。
2、singleton就是指单例,每个类只有一个实例
3、session和request都是在spring mvc里面的概念,这里感兴趣的同学可以网上搜罗下这两者的区别,简单的说,session是指整个会话的时间内有效,reqeust是指一次请求有效