Spring Data Conversion Service for MVC

While working on project I struggled bit with enabling Spring Data domain model conversion Service for Spring MVC.

What is this good for?

Controller is receiving id of an entity instance in database. This domain conversion service fetches this instance for controller according to its type. So application gets real instances in controller instead plain ids. This works recursively. It's therefore especially useful when processing form with many to one relation.

How to enable it

Just edit your spring configuration like this ...

Spring 3 XML configuration
<mvc:annotation-driven conversion-service="conversionService" />
<bean id="conversionService" class="org.springframework.core.convert.support.DefaultConversionService" />
<bean class="org.springframework.data.repository.support.DomainClassConverter">
 <constructor-arg ref="conversionService" />

Žádné komentáře: