ktor and spring-web integrate
- easy to migrate from spring-boot-web(or webflux)
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.theoxao</groupId>
<artifactId>spring-boot-ktor</artifactId>
<version>0.2.1-alpha</version>
</dependency>
@RestController
@RequestMapping("/ocr")
class OCRController(private val ocrService: OCRService) {
@PostMapping("/recognize")
suspend fun base64(@RequestParam("file") file: MultipartFile): String {
return ocrService.recognize(file)
}
}
- same with java code (of course, no suspend)
@RestController
@RequestMapping("/ocr/java")
public class OCRJavaController {
@Autowired
private OCRService ocrService;
@RequestMapping("/recognize")
public String base64(MultipartFile file){
return ocrService.recognize(file);
}
}
spring:
ktor:
port: 8080
enableTrace: false
engine: "Netty" //Netty and CIO only
staticRoot: "static"
templatesRoot: "templates"
- supported spring-web annotaiton
@Controller
@CookieValue
@RequestBody
@RequestHeader
@RequestMapping
@ResponseBody
@RestController
@GetMapping
@PostMapping
@DeleteMapping
@PutMapping
- request and response inject
fun base64(request:ApplicationRequest,response:ApplicationResponse): String ...