[英]Hierarchical Application Context and Standard-Scopes and Custom-Scopes
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 对于子组件,我创建了自己的“会话范围”实现(哈希映射,没有真正的清理等。urgs ),并通过“ CustomScopeConfigurer”将其范围注册为每个(手动启动)子组件的“ SESSION”。上下文...这样,我仍然可以在子上下文弹簧配置类中使用“常规” @Scope(value = WebApplicationContext.SCOPE_SESSION)方法
Q1: is this "handmade" scope a good idea? Q1:这个“手工”示波器是个好主意吗? :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"?
:D Q2:此“手工”范围应该是“会话范围”内的一种“转换范围”,但请记住,此范围在“会话”中存在N次,因此我们将其称为“会话-1”范围”,“ conversation-2-scope” ...“ conversation-N-scope” Q3:何时以及如何清除此类“ conversation-scope”?
Q4: is it necessary to register all the known scopes from "parent-context" in the "sub-context" like this: 问题4:是否有必要像这样在“子上下文”中注册“父上下文”中的所有已知范围:
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...? 您是否正在寻找WeakHashMap ...?
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. 我不知道所有的Spring废话:)-但是当我需要创建并稍后在使用Dagger2时自动释放子图时,上述操作很方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.