Skip to content

Commit 6df3025

Browse files
authored
RESTEASY-2500 - add example called resteasy-spring-rest-annotation (#50)
* RESTEASY-2500 - add example called `resteasy-spring-rest-annotation` * finish working on the example * minor fix * cleanup * fix spring-basic-example
1 parent f3f13fd commit 6df3025

File tree

8 files changed

+129
-3
lines changed

8 files changed

+129
-3
lines changed

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<module>resteasy-spring-basic</module>
1919
<module>resteasy-spring-customized</module>
2020
<module>resteasy-spring-undertow</module>
21+
<module>resteasy-spring-rest</module>
2122
<module>oreilly-jaxrs-2.0-workbook</module>
2223
<module>examples-jsapi</module>
2324
<module>smime</module>
@@ -103,6 +104,16 @@
103104
<artifactId>resteasy-undertow</artifactId>
104105
<version>${resteasy.ver}</version>
105106
</dependency>
107+
<dependency>
108+
<groupId>org.jboss.resteasy</groupId>
109+
<artifactId>resteasy-spring-web</artifactId>
110+
<version>${resteasy.ver}</version>
111+
</dependency>
112+
<dependency>
113+
<groupId>org.jboss.resteasy</groupId>
114+
<artifactId>resteasy-servlet-initializer</artifactId>
115+
<version>${resteasy.ver}</version>
116+
</dependency>
106117
<dependency>
107118
<groupId>org.jboss.resteasy</groupId>
108119
<artifactId>resteasy-client</artifactId>
@@ -248,6 +259,11 @@
248259
<scope>test</scope>
249260
<version>${junit.version}</version>
250261
</dependency>
262+
<dependency>
263+
<groupId>org.springframework</groupId>
264+
<artifactId>spring-web</artifactId>
265+
<version>${spring.version}</version>
266+
</dependency>
251267
<dependency>
252268
<groupId>org.springframework</groupId>
253269
<artifactId>spring-webmvc</artifactId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.springframework.stereotype.Component;
44

55
@Component
6-
public class FooService {
6+
public class FooBean {
77
public String hello() {
88
return "Hello, world!";
99
}

resteasy-spring-basic/src/main/java/org/jboss/resteasy/examples/springbasic/FooResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class FooResource {
1212

1313
@Autowired
14-
FooService fooService;
14+
FooBean fooBean;
1515

1616
@GET
1717
public String getFoo(@Context ServletContext context) {
@@ -21,6 +21,6 @@ public String getFoo(@Context ServletContext context) {
2121
@GET
2222
@Path("/hello")
2323
public String hello() {
24-
return fooService.hello();
24+
return fooBean.hello();
2525
}
2626
}

resteasy-spring-rest/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RESTEasy support of Spring REST annotations
2+
3+
The module shows an example of using RESTEasy to support Spring REST annotations.
4+
5+
## Building the project
6+
7+
```bash
8+
$ mvn clean install
9+
```
10+
11+
## Running the project and manually testing it
12+
13+
```bash
14+
$ mvn jetty:run
15+
```
16+
17+
Using the `curl` command to access this URL:
18+
19+
```bash
20+
$ curl http://localhost:8080/spring
21+
```
22+
23+
It will return `Spring is coming!` from server side. And the resource class from server side is using Spring REST annotations:
24+
25+
```java
26+
@RestController
27+
@RequestMapping("/spring")
28+
public class SpringRestAnnotationResource {
29+
30+
@GetMapping("/")
31+
public String get() {
32+
return "Spring is coming!";
33+
}
34+
}
35+
```
36+

resteasy-spring-rest/pom.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.jboss.resteasy</groupId>
7+
<artifactId>testable-examples-pom</artifactId>
8+
<version>4.0.1.Final-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<groupId>org.jboss.resteasy.examples</groupId>
12+
<artifactId>examples-resteasy-spring-rest</artifactId>
13+
<name>Example of Processing Spring Web REST annotations in RESTEasy</name>
14+
<packaging>war</packaging>
15+
<dependencies>
16+
<!-- This dependency is needed by servlet 3.0 container-->
17+
<dependency>
18+
<groupId>org.jboss.resteasy</groupId>
19+
<artifactId>resteasy-servlet-initializer</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.jboss.resteasy</groupId>
23+
<artifactId>resteasy-core-spi</artifactId>
24+
</dependency>
25+
<!-- This dependency supports Spring REST annotations-->
26+
<dependency>
27+
<groupId>org.jboss.resteasy</groupId>
28+
<artifactId>resteasy-spring-web</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-web</artifactId>
33+
</dependency>
34+
</dependencies>
35+
<build>
36+
<finalName>resteasy-spring-example-rest</finalName>
37+
</build>
38+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jboss.resteasy.examples.springrest;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
6+
@ApplicationPath("/")
7+
public class MyApplication extends Application {
8+
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jboss.resteasy.examples.springrest;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
@RestController
8+
@RequestMapping("/spring")
9+
public class SpringRestAnnotationResource {
10+
11+
@GetMapping("/")
12+
public String get() {
13+
return "Spring is coming!";
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
4+
<display-name>resteasy-spring-rest</display-name>
5+
6+
<context-param>
7+
<param-name>resteasy.scanned.resource.classes.with.builder</param-name>
8+
<param-value>
9+
org.jboss.resteasy.spi.metadata.SpringResourceBuilder:org.jboss.resteasy.examples.springrest.SpringRestAnnotationResource
10+
</param-value>
11+
</context-param>
12+
</web-app>

0 commit comments

Comments
 (0)