Skip to content

Commit

Permalink
RESTEASY-2500 - add example called resteasy-spring-rest-annotation (#…
Browse files Browse the repository at this point in the history
…50)

* RESTEASY-2500 - add example called `resteasy-spring-rest-annotation`

* finish working on the example

* minor fix

* cleanup

* fix spring-basic-example
  • Loading branch information
liweinan committed Feb 16, 2020
1 parent f3f13fd commit 6df3025
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 3 deletions.
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module>resteasy-spring-basic</module>
<module>resteasy-spring-customized</module>
<module>resteasy-spring-undertow</module>
<module>resteasy-spring-rest</module>
<module>oreilly-jaxrs-2.0-workbook</module>
<module>examples-jsapi</module>
<module>smime</module>
Expand Down Expand Up @@ -103,6 +104,16 @@
<artifactId>resteasy-undertow</artifactId>
<version>${resteasy.ver}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring-web</artifactId>
<version>${resteasy.ver}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>${resteasy.ver}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
Expand Down Expand Up @@ -248,6 +259,11 @@
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.stereotype.Component;

@Component
public class FooService {
public class FooBean {
public String hello() {
return "Hello, world!";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class FooResource {

@Autowired
FooService fooService;
FooBean fooBean;

@GET
public String getFoo(@Context ServletContext context) {
Expand All @@ -21,6 +21,6 @@ public String getFoo(@Context ServletContext context) {
@GET
@Path("/hello")
public String hello() {
return fooService.hello();
return fooBean.hello();
}
}
36 changes: 36 additions & 0 deletions resteasy-spring-rest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# RESTEasy support of Spring REST annotations

The module shows an example of using RESTEasy to support Spring REST annotations.

## Building the project

```bash
$ mvn clean install
```

## Running the project and manually testing it

```bash
$ mvn jetty:run
```

Using the `curl` command to access this URL:

```bash
$ curl http://localhost:8080/spring
```

It will return `Spring is coming!` from server side. And the resource class from server side is using Spring REST annotations:

```java
@RestController
@RequestMapping("/spring")
public class SpringRestAnnotationResource {

@GetMapping("/")
public String get() {
return "Spring is coming!";
}
}
```

38 changes: 38 additions & 0 deletions resteasy-spring-rest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.resteasy</groupId>
<artifactId>testable-examples-pom</artifactId>
<version>4.0.1.Final-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.jboss.resteasy.examples</groupId>
<artifactId>examples-resteasy-spring-rest</artifactId>
<name>Example of Processing Spring Web REST annotations in RESTEasy</name>
<packaging>war</packaging>
<dependencies>
<!-- This dependency is needed by servlet 3.0 container-->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core-spi</artifactId>
</dependency>
<!-- This dependency supports Spring REST annotations-->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>resteasy-spring-example-rest</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jboss.resteasy.examples.springrest;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jboss.resteasy.examples.springrest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/spring")
public class SpringRestAnnotationResource {

@GetMapping("/")
public String get() {
return "Spring is coming!";
}
}
12 changes: 12 additions & 0 deletions resteasy-spring-rest/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>resteasy-spring-rest</display-name>

<context-param>
<param-name>resteasy.scanned.resource.classes.with.builder</param-name>
<param-value>
org.jboss.resteasy.spi.metadata.SpringResourceBuilder:org.jboss.resteasy.examples.springrest.SpringRestAnnotationResource
</param-value>
</context-param>
</web-app>

0 comments on commit 6df3025

Please sign in to comment.