Make method accessible in GenericScope proxy target

Otherwise app crashes on first access of scoped proxy.

Fixes gh-261
This commit is contained in:
Dave Syer
2017-10-11 08:09:06 -04:00
parent 6149156fff
commit ccf613c29c
2 changed files with 9 additions and 5 deletions

View File

@@ -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,
@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,
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());
}

View File

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