Updated docs/README.
This commit is contained in:
68
README.md
68
README.md
@@ -1,70 +1,16 @@
|
||||
# Spring Data Rest Exporter
|
||||
# Spring Data Web Exporter
|
||||
|
||||
The Spring Data Rest exporter is a project that aims to make it easy to expose various
|
||||
services as Rest endpoints. The goal of the project is to provide a flexible and configurable
|
||||
mechanism for writing simple services that can expose arbitrary services over HTTP.
|
||||
The goal of the project is to provide a flexible and configurable mechanism for writing simple services that can be exposed over HTTP.
|
||||
|
||||
The first exporter implemented is a JPA Repository exporter. This takes your JPA repositories
|
||||
and front-ends them with HTTP, allowing you full CRUD capability over your entities, to include
|
||||
managing associations.
|
||||
The first exporter implemented is a JPA Repository exporter. This takes your JPA repositories and front-ends them with HTTP, allowing you full CRUD capability over your entities, to include managing associations.
|
||||
|
||||
### Installation
|
||||
|
||||
To use the Spring Data Rest exporter, first package your domain classes and repositories into a JAR
|
||||
file. Include some Spring XML configuration files in the `META-INF/spring-data-rest` directory (the
|
||||
file name should end with "-export.xml" to be picked up by the scanner). In that JAR file include
|
||||
an applicable EntityManager and DataSource and Repository configuration (using the special JPA
|
||||
Repository namespace).
|
||||
Installation instructions are in the wiki.
|
||||
|
||||
You can either deploy this JAR file into your Servlet container in a "shared" configuration, or you
|
||||
can add this JAR file (and any other application dependencies) to the exporter WAR file's `WEB-INF/lib`
|
||||
directory.
|
||||
* [https://github.com/springsource/spring-data-rest/wiki/jpa-repository-web-exporter](https://github.com/springsource/spring-data-rest/wiki/jpa-repository-web-exporter)
|
||||
|
||||
### Sample Configuration
|
||||
|
||||
The configuration used in testing looks like this:
|
||||
|
||||
##### META-INF/spring-data-rest/shared.xml
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
|
||||
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="generateDdl" value="true"/>
|
||||
<property name="database" value="HSQL"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="persistenceUnitName" value="jpa.sample"/>
|
||||
</bean>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
</bean>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL"/>
|
||||
|
||||
</beans>
|
||||
|
||||
##### META-INF/spring-data-rest/repositories-export.xml
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
|
||||
|
||||
<import resource="shared.xml"/>
|
||||
|
||||
<!-- Search for Repositories under this package name -->
|
||||
<jpa:repositories base-package="org.springframework.data.rest.test.webmvc"/>
|
||||
|
||||
</beans>
|
||||
### License
|
||||
|
||||
The Spring Data Web Exporter is [Apache 2.0 licensed](http://www.apache.org/licenses/LICENSE-2.0.html).
|
||||
@@ -4,7 +4,54 @@ The Spring Data JPA Repository Web Exporter allows you to export your [JPA Repos
|
||||
|
||||
### Installation
|
||||
|
||||
Installation is as simple as downloading a WAR file. To expose your Repositories to the exporter, include a Spring XML configuration file in the classpath. The filename should end with "-export.xml" and reside under the path `META-INF/spring-data-rest/`. Your configuration should include a properly-instaniated EntityManagerFactoryBean, an appropriate DataSource, and the appropriate repository configuration. It's easiest to use the special XML namespace for this purpose. An example configuration (named `WEB-INF/spring-data-rest/repositories-export.xml`) would look like something like this:
|
||||
#### Servlet environment
|
||||
|
||||
To use the Spring Data Web Exporter, you need to build a WAR file. Start by cloning the base web application project that contains the web.xml file you'll need to run the Web Exporter: [https://github.com/SpringSource/spring-data-rest-webmvc](https://github.com/SpringSource/spring-data-rest-webmvc).
|
||||
|
||||
git clone https://github.com/SpringSource/spring-data-rest-web.git
|
||||
cd spring-data-rest-web
|
||||
./gradlew war
|
||||
|
||||
Deploy the built WAR file to your servlet container:
|
||||
|
||||
cp build/libs/spring-data-rest-webmvc-1.0.0.BUILD-SNAPSHOT.war $TOMCAT_HOME/webapps/data.war
|
||||
cd $TOMCAT_HOME
|
||||
bin/catalina.sh run
|
||||
|
||||
The WAR file has a couple example domain classes and exposes a couple repositories by default. You can verify that this configuration is working by issuing an HTTP GET to the root of the web application:
|
||||
|
||||
curl -v http://localhost:8080/data/
|
||||
|
||||
In return, you should see:
|
||||
|
||||
> GET /data/ HTTP/1.1
|
||||
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
|
||||
> Host: localhost:8080
|
||||
> Accept: */*
|
||||
>
|
||||
< HTTP/1.1 200 OK
|
||||
< Server: Apache-Coyote/1.1
|
||||
< Content-Type: application/json;charset=ISO-8859-1
|
||||
< Content-Language: en-US
|
||||
< Content-Length: 257
|
||||
< Date: Mon, 16 Apr 2012 14:32:44 GMT
|
||||
<
|
||||
{
|
||||
"_links" : [ {
|
||||
"rel" : "address",
|
||||
"href" : "http://localhost:8080/data/address"
|
||||
}, {
|
||||
"rel" : "person",
|
||||
"href" : "http://localhost:8080/data/person"
|
||||
}, {
|
||||
"rel" : "profile",
|
||||
"href" : "http://localhost:8080/data/profile"
|
||||
} ]
|
||||
}
|
||||
|
||||
### Export Repositories
|
||||
|
||||
To expose your Repositories to the exporter, include a Spring XML configuration file in the classpath (e.g. in a client JAR or in `WEB-INF/classes`). The filename should end with "-export.xml" and reside under the path `META-INF/spring-data-rest/`. Your configuration should include a properly-instaniated EntityManagerFactoryBean, an appropriate DataSource, and the appropriate repository configuration. It's easiest to use the special XML namespace for this purpose. An example configuration (named `WEB-INF/spring-data-rest/repositories-export.xml`) would look like something like this:
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
@@ -125,6 +172,8 @@ Following the links for the "profiles" property gives us a list of links to the
|
||||
} ]
|
||||
}
|
||||
|
||||
In this case, the "profiles" property is a Map, so the "rel" value of the links is the key in the Map. The resource link, however, does not use the Map key in the URL. It is consistent with all other links to child resources and uses the ID of the child entity as the last component of the URL.
|
||||
|
||||
Retrieving the linked entity gives us a JSON representation of the entity, as well as the "self" link necessary to update and delete the entity.
|
||||
|
||||
curl -v http://localhost:8080/data/person/1/profiles/1
|
||||
|
||||
Reference in New Issue
Block a user