mercredi 15 avril 2015

Spring Data REST with Spring MVC: Adding RepositoryRestMvcConfiguration to existing DispatcherServlet

I have an existing Spring MVC Application with a DispatcherServlet and an XML based configuration.


Now I would like to integrate Spring Data REST but I dont know how to do this in a clean way. I added



<context:component-scan>...</context:component-scan>


so my RestControllers are found but I fail in adding a RepositoryRestMvcConfiguration config. I tried the annotation driven approach which doesnt work



@Configuration
public class RestConfiguration extends RepositoryRestMvcConfiguration {
...
}


and the



<bean class="com.mypackage.rest.RestConfiguration" />


approach is not working either.


I also tried the follwing in the web.xml



<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mypackage.rest.RestConfiguration</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


Strange thing is, a method annotated with @PostConstruct is called, but non of the configure* methods.


In the docs for Spring Data REST is a chapter where it is explained how to add a Spring Data REST to a Spring MVC application in code. It also says



The equivalent of the above in a standard web.xml will also work identically to this configuration if you are still in a servlet 2.5 environment.



How do you do this?


Aucun commentaire:

Enregistrer un commentaire