spring-boot示例
spring-boot接入Resteasy
前言
这里演示如何在spring-boot
中接入resteasy
框架。
相关版本
依赖 | 版本 |
---|---|
spring-boot | 2.7.9 |
resteasy-spring-boot-starter | 5.0.0.Final |
一、resteasy是什么?
RESTEasy是一个JBoss/Red Hat项目,它提供了各种框架来帮助您构建RESTful Web服务和RESTful Java应用程序。它是Jakarta RESTful Web Services的实现,这是一个Eclipse Foundation规范,通过HTTP协议为RESTful Web服务提供Java API。
此外,RESTEasy还实现了MicroProfile REST客户端规范API(本人英文不行,纯纯百度翻译)。
我自己的理解就是一个RESTful Web框架。
resteasy官方网站:https://resteasy.dev
二、接入步骤
1.创建项目(略)
有需要的可以去源代码查看
2.添加依赖
<!-- resteasy -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>5.0.0.Final</version>
</dependency>
<!-- spring-boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.7.9</version>
</dependency>
3.添加启动类
package work.silian.resteasy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ResteasyApplication {
public static void main(String[] args) {
SpringApplication.run( ResteasyApplication.class ,args );
}
}
4.添加测试类
package work.silian.resteasy.controller;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.springframework.stereotype.Controller;
@Path("/test")
@Controller
public class TestController {
@Path("/demo")
@GET
public String test() {
System.out.println("test");
return "helloworld";
}
}
5. 启动与测试
执行ResteasyApplication
类的main
方法启动,访问http://127.0.0.1:8080/test/demo
即可。
总结
以上主要是对spring-boot接入resteasy的记录,防止自己遗忘没有地方查找资料。
源代码
https://gitee.com/yichanggeng/spring-boot-demo/tree/develop/spring-boot-resteasy