Q:

How to configure a Bean prototype scoped provider to use session information on Bean creation?

I need to provide beans based on session information every time the proxy is acessed to obtain the instance. How I can do that?
For now I tried the following. For example:
The first class defines a session scoped bean.
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class BeanSession implements Serializable {

    private Serializable rootState;

    public <T extends Serializable> T getRootState() {
        return (T) rootState;
    }

    public void setRootState(Serializable rootState) {
        this.rootState = rootState;
    }
}

The second class has some logic related to their domain and also knows how to provide the information. The bean must be a created every time because the information can change during the thread processing. Therefore, every time the Attribute1 is acessed I will be sure to get the bean with fresh information.
@Service
public class Attribute1Service {

    @Resource
    private BeanSession beanSession;

    public void setDefaultValue() {
        Configuration configuration = beanSession.getRootState();
        configuration.getAttribute1().setValue("VALUE 1");
    }

    @Bean
    public Attribute1 attribute1() {
        Configuration configuration = beanSession.getRootState();
        return configuration.getAttribute1();
    }

}

Finally, the third class declares the attribute1 as dependency to execute their own logic.
@Service
public class Attribute2Service {

    @Resource
    private BeanSession beanSession;

    @Resource
    private Processor processor;

    @Resource
    private Attribute1 attribute1;

    public void defineAttribute2() {
        Configuration configuration = beanSession.getRootState();
        String value = processor.getValue(configuration, attribute1);
        configuration.getAttribute2().setValue(value);
    }

    public void defineAttribute3() {
        Configuration configuration = beanSession.getRootState();
        String value = processor.getValue(configuration, attribute1);
        configuration.getAttribute3().setValue(value);
    }

}

However, the problem is that during attribute1 creation I am getting the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Attribute2Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attribute1' defined in class path resource [Attribute1Service.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [String]: Factory method 'attribute1' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.beanSession': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
...

I don't want to access attribute1 information from beanSession on Attribute2Service because it will create a hard coupling between the information providers and consumers.

A:

Based on the insights given by Alexander.Furer. I created my own scope and managed it to call the bean provider to have the fresh bean in every access of Attribute1 methods.
To this, I extended the following Scope:
// Register scope as "runtime"
public class RuntimeScope implements Scope {

    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        return objectFactory.getObject();
    }

    ...
}

The new Attribute1 service:
@Service
public class Attribute1Service {

    @Resource
    private BeanSession beanSession;

    public void setDefaultValue() {
        Configuration configuration = beanSession.getRootState();
        configuration.getAttribute1().setValue("VALUE 1");
    }

    @Bean
    @Scope(value = "runtime", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Attribute1 attribute1() {
        Configuration configuration = beanSession.getRootState();
        return configuration.getAttribute1();
    }

}

The consumer Attribute2service:
@Service
public class Attribute2Service {

    @Resource
    private BeanSession beanSession;

    @Resource
    private Processor processor;

    @Resource
    private Attribute1 attribute1;

    public void defineAttribute2() {
        Configuration configuration = beanSession.getRootState();
        String value = processor.getValue(configuration, attribute1.getValue()); // Will call Attribute1 service to require the fresh bean
        configuration.getAttribute2().setValue(value);
    }

    public void defineAttribute3() {
        Configuration configuration = beanSession.getRootState();
        String value = processor.getValue(configuration, attribute1.getValue()); // Will call Attribute1 service to require the fresh bean
        configuration.getAttribute3().setValue(value);
    }

}

The problem I wasn't seeing is that Attribute1 should be a proxy to handle the bean instantiation. Therefore, creating my own scope I can guarantee that accesses to attribute1 (made by Attribute2Service with attribute1.getValue()) methods will create a fresh bean (provided by Attribute1Service).

