Skip to content

Commit 82e27c8

Browse files
committed
added example accessing a spring data rest api with feign
1 parent c85f849 commit 82e27c8

13 files changed

Lines changed: 496 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.gradle
2+
/build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
nbproject/private/
21+
build/
22+
nbbuild/
23+
dist/
24+
nbdist/
25+
.nb-gradle/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
buildscript {
2+
ext {
3+
springBootVersion = '1.5.6.RELEASE'
4+
}
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'eclipse'
15+
apply plugin: 'org.springframework.boot'
16+
17+
version = '0.0.1-SNAPSHOT'
18+
sourceCompatibility = 1.8
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
25+
ext {
26+
springCloudVersion = 'Dalston.SR2'
27+
}
28+
29+
dependencies {
30+
compile('org.springframework.cloud:spring-cloud-starter-feign')
31+
compile('org.springframework.boot:spring-boot-starter-hateoas')
32+
testCompile('org.springframework.boot:spring-boot-starter-test')
33+
}
34+
35+
dependencyManagement {
36+
imports {
37+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
38+
}
39+
}
40+
41+
bootRun{
42+
jvmArgs = ["-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006"]
43+
}

feign-with-spring-data-rest/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

feign-with-spring-data-rest/gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.demo;
2+
3+
public class Address {
4+
5+
private long id;
6+
7+
private String street;
8+
9+
public long getId() {
10+
return id;
11+
}
12+
13+
public void setId(long id) {
14+
this.id = id;
15+
}
16+
17+
public String getStreet() {
18+
return street;
19+
}
20+
21+
public void setStreet(String street) {
22+
this.street = street;
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.demo;
2+
3+
import org.springframework.cloud.netflix.feign.FeignClient;
4+
import org.springframework.hateoas.Resource;
5+
import org.springframework.hateoas.Resources;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
11+
@FeignClient(value = "addresses", path = "/addresses_mto")
12+
public interface AddressClient {
13+
14+
@RequestMapping(method = RequestMethod.GET, path = "/")
15+
Resources<Address> getAddresses();
16+
17+
@RequestMapping(method = RequestMethod.GET, path = "/{id}")
18+
Resource<Address> getAddress(@PathVariable("id") long id);
19+
20+
@RequestMapping(method = RequestMethod.PUT, consumes = "text/uri-list", path="/{addressId}/customer")
21+
Resource<Address> associateWithCustomer(@PathVariable("addressId") long addressId, @RequestBody String customerUri);
22+
23+
@RequestMapping(method = RequestMethod.GET, path="/{addressId}/customer")
24+
Resource<Customer> getCustomer(@PathVariable("addressId") long addressId);
25+
26+
}

0 commit comments

Comments
 (0)