Skip to content

Commit 51577b2

Browse files
committed
actually delegate from resolveContextualObject to resolveReference
1 parent 05bebb0 commit 51577b2

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

org.springframework.web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public void registerDestructionCallback(String name, Runnable callback) {
6464
}
6565

6666
public Object resolveContextualObject(String key) {
67-
return null;
67+
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
68+
return attributes.resolveReference(key);
6869
}
6970

7071

org.springframework.web/src/test/java/org/springframework/web/context/request/RequestScopeTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2008 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,14 +25,14 @@
2525
import org.springframework.beans.factory.FactoryBean;
2626
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2727
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
28+
import org.springframework.context.expression.StandardBeanExpressionResolver;
2829
import org.springframework.core.io.ClassPathResource;
2930
import org.springframework.mock.web.MockHttpServletRequest;
3031

3132
/**
3233
* @author Rob Harrop
3334
* @author Juergen Hoeller
3435
* @author Mark Fisher
35-
* @since 2.0
3636
*/
3737
public class RequestScopeTests extends TestCase {
3838

@@ -41,20 +41,23 @@ public class RequestScopeTests extends TestCase {
4141
protected void setUp() throws Exception {
4242
this.beanFactory = new DefaultListableBeanFactory();
4343
this.beanFactory.registerScope("request", new RequestScope());
44+
this.beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver());
4445
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
4546
reader.loadBeanDefinitions(new ClassPathResource("requestScopeTests.xml", getClass()));
4647
this.beanFactory.preInstantiateSingletons();
4748
}
4849

4950
public void testGetFromScope() throws Exception {
5051
MockHttpServletRequest request = new MockHttpServletRequest();
52+
request.setContextPath("/path");
5153
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
5254
RequestContextHolder.setRequestAttributes(requestAttributes);
5355

5456
try {
5557
String name = "requestScopedObject";
5658
assertNull(request.getAttribute(name));
5759
TestBean bean = (TestBean) this.beanFactory.getBean(name);
60+
assertEquals("/path", bean.getName());
5861
assertSame(bean, request.getAttribute(name));
5962
assertSame(bean, this.beanFactory.getBean(name));
6063
}

org.springframework.web/src/test/resources/org/springframework/web/context/request/requestScopeTests.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
xsi:schemaLocation="http://www.springframework.org/schema/beans
55
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
66

7-
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request"/>
7+
<bean id="requestScopedObject" class="org.springframework.beans.TestBean" scope="request">
8+
<property name="name" value="#{request.contextPath}"/>
9+
</bean>
810

911
<bean id="requestScopedDisposableObject" class="org.springframework.beans.DerivedTestBean" scope="request"/>
1012

0 commit comments

Comments
 (0)