Skip to content

Commit

Permalink
avoid calling other APIs when InternalUserSessionData is initializing
Browse files Browse the repository at this point in the history
#713

This would fix:
Caused by:
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'scopedTarget.internalUserSessionData':
Requested bean is currently in creation: Is there an unresolvable
circular reference?
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at
org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.getTarget(CglibAopProxy.java:705)
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at
de.metas.ui.web.session.InternalUserSessionData$$EnhancerBySpringCGLIB$$52d45398.getCtx(<generated>)
at de.metas.ui.web.session.UserSession.getCtx(UserSession.java:175)
at
de.metas.ui.web.session.WebRestApiContextProvider.getActualContext(WebRestApiContextProvider.java:104)
at
de.metas.ui.web.session.WebRestApiContextProvider.access$000(WebRestApiContextProvider.java:44)
at
de.metas.ui.web.session.WebRestApiContextProvider$1.getDelegate(WebRestApiContextProvider.java:54)
at
org.adempiere.util.AbstractPropertiesProxy.getProperty(AbstractPropertiesProxy.java:238)
at org.compiere.util.Env.getProperty(Env.java:2240)
at org.compiere.util.Env.getContext(Env.java:2191)
at org.compiere.util.Env.getContext(Env.java:824)
at org.compiere.util.Env.getContextAsInt(Env.java:896)
at
de.metas.logging.SysConfigLoggerCustomizer.customize(SysConfigLoggerCustomizer.java:93)
at de.metas.logging.LogManager.getLogger(LogManager.java:32)
at de.metas.i18n.ADLanguageList.<clinit>(ADLanguageList.java:64)
... 134 common frames omitted
  • Loading branch information
teosarca committed Dec 16, 2017
1 parent 9424eee commit 086d3c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/de/metas/ui/web/session/InternalUserSessionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Properties;

import org.compiere.util.Env;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.ScopedProxyMode;
Expand Down Expand Up @@ -55,7 +54,7 @@
@Primary
@SessionScope(proxyMode = ScopedProxyMode.TARGET_CLASS)
@lombok.Data
/* package */ class InternalUserSessionData implements Serializable, InitializingBean
/* package */ class InternalUserSessionData implements Serializable
{
private static final long serialVersionUID = 4046535476486036184L;

Expand All @@ -67,6 +66,7 @@

//
// Actual session data
private volatile boolean initialized = false;
private String sessionId = null;
private UserPreference userPreference = null;
private boolean loggedIn = false;
Expand Down Expand Up @@ -114,8 +114,22 @@ public InternalUserSessionData()
UserSession.logger.trace("User session created: {}", this);
}

@Override
public void afterPropertiesSet() throws Exception
void initializeIfNeeded()
{
if (!initialized)
{
synchronized (this)
{
if (!initialized)
{
initializeNow();
initialized = true;
}
}
}
}

private void initializeNow()
{
//
// Set initial properties
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/metas/ui/web/session/UserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public UserSession(final ApplicationEventPublisher eventPublisher)

private InternalUserSessionData getData()
{
_data.initializeIfNeeded();
return _data;
}

Expand Down

0 comments on commit 086d3c1

Please sign in to comment.