Browse Source

Make method accessible in GenericScope proxy target

Otherwise app crashes on first access of scoped proxy.

Fixes gh-261
pull/267/merge
Dave Syer 7 years ago
parent
commit
ccf613c29c
  1. 11
      spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java
  2. 3
      spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java

11
spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
package org.springframework.cloud.context.scope;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -453,9 +454,10 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor, @@ -453,9 +454,10 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
if (AopUtils.isEqualsMethod(invocation.getMethod())
|| AopUtils.isToStringMethod(invocation.getMethod())
|| AopUtils.isHashCodeMethod(invocation.getMethod())) {
Method method = invocation.getMethod();
if (AopUtils.isEqualsMethod(method)
|| AopUtils.isToStringMethod(method)
|| AopUtils.isHashCodeMethod(method)) {
return invocation.proceed();
}
Object proxy = getObject();
@ -464,7 +466,8 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor, @@ -464,7 +466,8 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor,
try {
if (proxy instanceof Advised) {
Advised advised = (Advised) proxy;
return ReflectionUtils.invokeMethod(invocation.getMethod(),
ReflectionUtils.makeAccessible(method);
return ReflectionUtils.invokeMethod(method,
advised.getTargetSource().getTarget(),
invocation.getArguments());
}

3
spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java

@ -160,7 +160,8 @@ public class RefreshScopeConfigurationTests { @@ -160,7 +160,8 @@ public class RefreshScopeConfigurationTests {
String message;
@RequestMapping("/")
public String hello() {
// Deliberately use package scope
String hello() {
return message;
}

Loading…
Cancel
Save