Overriding Riot default

How to use the override namespace

Most Riot modules provide Spring configuration files that add beans to the three ApplicationContexts (riot-servlet, website-servlet and the root context). The files are located in the /META-INF/riot folder of the module's JAR file and loaded via Spring's classpath*: discovery mechanism.

Overwriting properties

To overwrite a bean provided by module, you can place a bean with the same id in your project's corresponding XML file. A drawback is that you have to copy the whole bean definition, even if you just want to overwrite a single property. You can avoid that by using Riot's override namespace:

<override:properties ref="someBean">
  <property name="foo" value="bar" />
</override:properties>

This works like Spring's PropertyOverrideConfigurer but isn't limited to simple values, you may use all property sub-elements supported by Spring, like ref, list, map, etc.

Injecting values into collections

The override namespace can be used to insert values into existing collections:

<override:add ref="someBean" property="someList">
  <ref bean="foo" />
  <bean class="eg.Bar" />
</override:add>

And even with beans that are Collections themselves:

<util:list id="someList">
  ...
</utl:list>

<override:add ref="someList">
  <value>newValue</value>
</override:add>

This does not only work for Lists and Sets, but also for Maps:

<override:put ref="someBean" property="someMap">
  <entry name="foo" local="someBean" />
</override:put>

Replacing a bean while preserving its configuration

Another useful feature is that you can change the class of a defined bean while preserving the configured properties:

<override:bean ref="sessionFactory" merge="true" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</override:bean>