I have used a SimpleUrlHandlerMapping bean in this example but the problem could relate to any bean that takes a Properties as an argument. My problem is that I would like to split the creation of my properties into different files to make it easier to manage and share resources across projects.
So my question is how do I join together properties in order to populate another properties property?
Best shown with an example. Currently I have all my controllers in the same file which i need to duplicate for different webapps.
webapp 1:
and webapp2:Code:<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <!-- foo module --> <prop key="/getfoo.html">getFooController</prop> <!-- bar module --> <prop key="/getbar.html">getBarController</prop> <prop key="/listbar.html">listBarController</prop> </props> </property> </bean>
I would like to refactor it into:Code:<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <!-- foo module --> <prop key="/getfoo.html">getFooController</prop> <!-- war module --> <prop key="/getwar.html">getWarController</prop> <prop key="/setwar.html">setWarController</prop> </props> </property> </bean>
Code:<bean id="fooprops" class="something.that.does.this"> <property name="mappings"> <props> <!-- foo module --> <prop key="/getfoo.html">getFooController</prop> </props> </property> </bean>Code:<bean id="barprops" class="something.that.does.this"> <property name="mappings"> <props> <!-- bar module --> <prop key="/getbar.html">getBarController</prop> <prop key="/listbar.html">listBarController</prop> </props> </property> </bean>Now my webapp config is:Code:<bean id="warprops" class="something.that.does.this"> <property name="mappings"> <props> <!-- bar module --> <prop key="/getwar.html">getWarController</prop> <prop key="/setwar.html">setWarController</prop> </props> </property> </bean>
webapp 1:
and webapp2 becomesCode:<import resource="classpath:com.package.foo"/> <import resource="classpath:com.package.bar"/> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props-joined> fooprops barprops </props-joined> </property> </bean>
I know it's not like this, but you see what I mean. Is this possible? Is this how people do it or is there a better way?Code:<import resource="classpath:com.package.foo"/> <import resource="classpath:com.package.war"/> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props-joined> fooprops warprops </props-joined> </property> </bean>


Reply With Quote