You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Re-allow merge of util:map list, set, ... based on the same bean ID [SPR-5199] #9872
For the sake of clarity/modularisation in my XML I am trying to separate out certain service definitions into separate files. It would be nice to see the re-emergence of 'merge' on the util: collection definitions in a way that definitions with the same ID are merged.
For example (hope this submits in a readable way):
The MyServiceProcedureProvider class is a POJO that encapsulates a Map with a
getter and setter.
NOTE: This solution has been made specifically for a single service that implements the command pattern but can be genericized for any situation similar to that described in the original post.
Activity
spring-projects-issues commentedon Apr 12, 2010
Philip Graham commented
Not sure if this is still an issue in more recent versions of Spring but for those of us stuck using 2.5 here is a workaround I've come up with:
[services.xml]
<bean id="serviceProvider" class="com.company.server.MyServiceImpl" />
[service1.xml]
<bean class="com.company.server.MyServiceProcedureProvider">
<property name="procedures">
<map>
<entry key="com.company.mod1.server.ServiceProvider1" value-ref="serviceProvider1" />
...
</map>
</property>
</bean>
<bean id="serviceProvider1" class="com.company.mod1.server.ServiceProvider1" >
...
</bean>
[service2.xml]
<bean class="com.company.server.MyServiceProcedureProvider">
<property name="procedures">
<map>
<entry key="com.company.mod2.server.ServiceProvider2" value-ref="serviceProvider2" />
...
</map>
</property>
</bean>
<bean id="serviceProvider2" class="com.company.mod1.server.ServiceProvider2" >
...
</bean>
Then the MyServiceImpl class implements ApplicationContextAware and uses getBeansOfType() to merge the maps together:
public class MyServiceImpl implements RemoteService, ApplicationContextAware {
private Map procedures = new HashMap();
public void setApplicationContext(ApplicationContext ac) {
Map providers = ac.getBeansOfType(MyServiceProcedureProvider.class);
for (Object provider : providers.values()) {
procedures.putAll((MyServiceProcedureProvider) provider).getProcedures());
}
}
/*
*/
// ... Delegate the service provider
}
The MyServiceProcedureProvider class is a POJO that encapsulates a Map with a
getter and setter.
NOTE: This solution has been made specifically for a single service that implements the command pattern but can be genericized for any situation similar to that described in the original post.
spring-projects-issues commentedon Apr 3, 2011
Chris Beams commented
Duplicates #11189