Search code examples
xmlmavenspring-dataspring-data-jpaspring-data-rest

How to configure and enable Spring Data REST using XML?


I guess I'm old school, but I prefer XML configuration over JavaConfig.

How do I correctly configure Spring Data REST using Maven and only XML Spring configuration files?

I have a simple app up and running with Postgres, Hibernate, a Spring Data JPA repository, and a Spring MVC controller.


Solution

  • If using spring-data-rest-webmvc version 1.1.0.M1...

    in applicationContext.xml, you need:

    <jpa:repositories base-package="my.packagename.repository"/>
    

    and in web.xml, you need:

    <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    

    SDR 1.1.0.M1 seems to require:

    spring-data-jpa 1.3.5.RELEASE
    spring-webmvc 3.2.7.RELEASE
    spring-hateoas 0.8.0.RELEASE