spring 官方文档,学习笔记
2015-11-02 10:24
477 查看
scope 相关:
and
do exactly the same thing, namely bind the HTTP request object to the
is servicing that request. This makes beans that are request- and session-scoped available further down the call chain.
scope 的五种状态中的,singleton 和 prototype 不用做特殊配置,至于 request,session, global session 则需要相关配置,如果使用spring web mvc 框架自动配置,如果使用其他的 比如 struts 则需要在web.xml 里 配置 request 监听器,
对于老的web 服务器 如果不起作用,则配置 过滤器
and
do exactly the same thing, namely bind the HTTP request object to the
is servicing that request. This makes beans that are request- and session-scoped available further down the call chain.
单例类引用原型类问题:
由于单例只创建一次,则如果其中有对原型类 的依赖,原型也只会创建一次,如果想该单例的原型属性每次都新创建,则需要方法注入。
单例类注入request , session ,global session scope 的类时,需要加代理 :
xml 配置文件使用property文件的例子:
property 文件格式:
DispatcherServlet,
RequestContextListener,
and
RequestContextFilterall
do exactly the same thing, namely bind the HTTP request object to the
Threadthat
is servicing that request. This makes beans that are request- and session-scoped available further down the call chain.
scope 的五种状态中的,singleton 和 prototype 不用做特殊配置,至于 request,session, global session 则需要相关配置,如果使用spring web mvc 框架自动配置,如果使用其他的 比如 struts 则需要在web.xml 里 配置 request 监听器,
<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
对于老的web 服务器 如果不起作用,则配置 过滤器
<filter> <filter-name>requestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
DispatcherServlet,
RequestContextListener,
and
RequestContextFilterall
do exactly the same thing, namely bind the HTTP request object to the
Threadthat
is servicing that request. This makes beans that are request- and session-scoped available further down the call chain.
单例类引用原型类问题:
由于单例只创建一次,则如果其中有对原型类 的依赖,原型也只会创建一次,如果想该单例的原型属性每次都新创建,则需要方法注入。
单例类注入request , session ,global session scope 的类时,需要加代理 :
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"> <aop:scoped-proxy/> </bean> <bean id="userManager" class="com.foo.UserManager"> <property name="userPreferences" ref="userPreferences"/> </bean>
xml 配置文件使用property文件的例子:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:com/foo/jdbc.properties"/> </bean> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean>
property 文件格式:
jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.url=jdbc:hsqldb:hsql://production:9002 jdbc.username=sa jdbc.password=root
相关文章推荐
- 根据json数据书写javabean
- java replace和replaceAll区别
- Spring体系结构介绍
- 在eclipse中执行数据库脚本
- struts2中s:select标签的使用
- Struts2版本更新报错:>>> ActionContextCleanUp <<< is deprecated! Please use the new filters!
- JAVA移位运算,INT类型颜色到RGB转换
- struts2 package 属性说明
- 浅谈 Java 性能优化
- struts.xml配置文件(package,namespace,action)
- Java序列化与反序列化的总结
- java POI中一些颜色值
- Eclipse ADT 与Android Studio 在放置jar库-资源文件-so文件的区别
- eclipse中签名打包
- 关于maven+springMVC+mybatis搭建的web项目问题
- Java基础笔试题2
- eclipse设置自定义快捷键
- 闰平年简介及计算过程描述 - Java代码实现
- 详解Spring中的CharacterEncodingFilter
- Spring MVC入门(1)---配置