This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Restlight for Spring

esa.restlight.spring.Restlight4SpringRestlight架构中的Restlight for Srping模块的入口类, 在Restlight Core 基础上增强了自动配置功能

  • Route自动配置
  • Filter自动配置
  • Controller自动配置
  • ControllerAdvice自动配置
  • HandlerInterceptor自动配置
  • ExceptionHandler自动配置
  • ArgumentResolver自动配置
  • ArgumentResolverAdvice自动配置
  • ReturnValueResolver自动配置
  • ReturnValueResolverAdvice自动配置
  • RequestSerializer自动配置
  • ResposneSerializer自动配置
  • Validator自动配置

1 - Quick Start

引入依赖

<dependency>
	<groupId>io.esastack</groupId>
	<artifactId>restlight-spring</artifactId>
	<version>${restlight.version}</version>
</dependency>

<dependency>
	<groupId>io.esastack</groupId>
	<artifactId>restlight-springmvc-provider</artifactId>
	<version>${restlight.version}</version>
</dependency>

编写Controller并注入Spring

// Spring容器扫描并注入
@Controller
@RequestMapping("/hello")
public class HelloController {

    @GetMapping(value = "/restlight")
    public String restlight() {
        return "Hello Restlight!";
    }
}

使用Restlight4Spring启动Server

ApplicationContext context = ...
Restlight4Spring.forServer(context)
        .daemon(false)
        .server()
        .start();

启动并访问: http://localhost:8080/hello 即可看到输出:

Hello Restlight!