my question is a little bit complicated :) I will try to explain my setup ...
this seems to work so far
but now I investigated a BIG memory leak :( I think I found the problem ...
for the sub-components I created my own "session-scoped" implementation (hash-map, no real cleanup etc. urgs ) and I registered this scoped via "CustomScopeConfigurer" as "SESSION" for each of my (manually started) sub-contexts ... with this I can still use the "normal" @Scope(value = WebApplicationContext.SCOPE_SESSION) approach in my sub-context spring-configuration classes
Q1: is this "handmade" scope a good idea? :D Q2: this "handmade" scope should be a kind of "conversion-scope" inside a "session-scope" but keep in mind this scope exists N times in a "session", so lets call it "conversation-1-scope", "conversation-2-scope" ... "conversation-N-scope" Q3: when and how can I cleanup such a "conversation-scope"?
Q4: is it necessary to register all the known scopes from "parent-context" in the "sub-context" like this:
final ConfigurableListableBeanFactory parentBeanFactory = ((AbstractApplicationContext) parentSpringContext).getBeanFactory();
final ConfigurableListableBeanFactory beanFactory = springApplicationContext.getBeanFactory();
final String[] scopeNames = parentBeanFactory.getRegisteredScopeNames();
for (final String scopeName : scopeNames) {
final Scope scope = parentBeanFactory.getRegisteredScope(scopeName);
beanFactory.registerScope(scopeName, scope);
}
Here is a visualization of my "structure":
TOP-LEVEL-Context |-* session-scoped beans |-* singleton beans (HelloWorldService) | |->SUB1-Context | |-* session-scoped beans (FooBarService - depends on HelloWorldService) | |-* singleton beans | |->SUB2-Context | |-* session-scoped beans (FooBarService - depends on HelloWorldService) | |-* singleton beans | |->...
Any hint would be awesome :)
Kind regards Andreas
Are you looking for WeakHashMap by any chance...?
I have no idea of all the Spring crap :) - but the aforementioned thing comes in handy when I need to create and later automatically release subgraphs when using Dagger2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.