Skip to content
Snippets Groups Projects
Commit a104838b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when spring return a proxy we need to unwrap it to obtain original class object

parent 63060613
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!499Spring config update
Pipeline #7404 passed
......@@ -14,6 +14,8 @@ import java.util.concurrent.ThreadFactory;
import javax.annotation.PostConstruct;
import org.apache.log4j.Logger;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
......@@ -141,6 +143,7 @@ public class PermanentDatabaseLevelCache extends XmlParser
try {
Class<?> clazz = Class.forName(type.getClassName());
Object object = applicationContext.getAutowireCapableBeanFactory().createBean(clazz);
object = unwrapProxy(object);
if (object instanceof CachableInterface) {
cachableInterface = (CachableInterface) object;
} else {
......@@ -182,6 +185,29 @@ public class PermanentDatabaseLevelCache extends XmlParser
}
/**
* http://forum.spring.io/forum/spring-projects/aop/52011-need-to-unwrap-a-proxy-to-get-the-object-being-proxied
*
* @param bean
* @return
* @throws Exception
*/
private final Object unwrapProxy(Object bean) throws Exception {
/*
* If the given object is a proxy, set the return value as the object being
* proxied, otherwise return the given object.
*/
if (AopUtils.isAopProxy(bean) && bean instanceof Advised) {
Advised advised = (Advised) bean;
bean = advised.getTargetSource().getTarget();
}
return bean;
}
/**
* This class represents new thread task for adding entry to database.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment