我的问题有点复杂:)我会尝试解释我的设置......
到目前为止似乎有效
但现在我调查了一个大内存泄漏:(我想我发现了问题...
我创建了自己的"会话范围的子组件"实现(hash-map,没有真正的清理等等。 urgs )并且我通过" CustomScopeConfigurer"注册了这个范围。 as" SESSION"对于我的每个(手动启动的)子上下文......有了这个,我仍然可以使用" normal"我的子上下文spring-configuration类中的@Scope(value = WebApplicationContext.SCOPE_SESSION)方法
Q1:这是"手工制作"范围好主意? :d Q2:这个"手工制作"范围应该是一种转换范围"在"会话范围内"但请记住,这个范围在"会话"中存在N次,所以我们称之为" conversation-1-scope"," conversation-2-scope" ......"对话-N-scope" 问题3:何时以及如何清理这样一个"会话范围"?
问题4:是否有必要注册来自" parent-context"的所有已知范围。在"子背景"像这样:
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);
}
这是我"结构的可视化":
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 | |->...
任何暗示都很棒:)
亲切的问候 安德烈亚斯
答案 0 :(得分:0)
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.