actually delegate from resolveContextualObject to resolveReference
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@313 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
e6f75f212d
commit
56e86e533a
|
|
@ -64,7 +64,8 @@ public abstract class AbstractRequestAttributesScope implements Scope {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveContextualObject(String key) {
|
public Object resolveContextualObject(String key) {
|
||||||
return null;
|
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
|
||||||
|
return attributes.resolveReference(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2008 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,6 +25,7 @@ import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
|
import org.springframework.context.expression.StandardBeanExpressionResolver;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
|
|
@ -32,7 +33,6 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @since 2.0
|
|
||||||
*/
|
*/
|
||||||
public class RequestScopeTests extends TestCase {
|
public class RequestScopeTests extends TestCase {
|
||||||
|
|
||||||
|
|
@ -41,6 +41,7 @@ public class RequestScopeTests extends TestCase {
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
this.beanFactory = new DefaultListableBeanFactory();
|
||||||
this.beanFactory.registerScope("request", new RequestScope());
|
this.beanFactory.registerScope("request", new RequestScope());
|
||||||
|
this.beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver());
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("requestScopeTests.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("requestScopeTests.xml", getClass()));
|
||||||
this.beanFactory.preInstantiateSingletons();
|
this.beanFactory.preInstantiateSingletons();
|
||||||
|
|
@ -48,6 +49,7 @@ public class RequestScopeTests extends TestCase {
|
||||||
|
|
||||||
public void testGetFromScope() throws Exception {
|
public void testGetFromScope() throws Exception {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
request.setContextPath("/path");
|
||||||
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
|
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
|
||||||
RequestContextHolder.setRequestAttributes(requestAttributes);
|
RequestContextHolder.setRequestAttributes(requestAttributes);
|
||||||
|
|
||||||
|
|
@ -55,6 +57,7 @@ public class RequestScopeTests extends TestCase {
|
||||||
String name = "requestScopedObject";
|
String name = "requestScopedObject";
|
||||||
assertNull(request.getAttribute(name));
|
assertNull(request.getAttribute(name));
|
||||||
TestBean bean = (TestBean) this.beanFactory.getBean(name);
|
TestBean bean = (TestBean) this.beanFactory.getBean(name);
|
||||||
|
assertEquals("/path", bean.getName());
|
||||||
assertSame(bean, request.getAttribute(name));
|
assertSame(bean, request.getAttribute(name));
|
||||||
assertSame(bean, this.beanFactory.getBean(name));
|
assertSame(bean, this.beanFactory.getBean(name));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||||
|
|
||||||
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request"/>
|
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request">
|
||||||
|
<property name="name" value="#{request.contextPath}"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="requestScopedDisposableObject" class="org.springframework.beans.DerivedTestBean" scope="request"/>
|
<bean id="requestScopedDisposableObject" class="org.springframework.beans.DerivedTestBean" scope="request"/>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue