今天我们尝试Spring Boot整合Scala,并决定建立一个非常简单的Spring Boot微服务,使用Scala作为编程语言进行编码构建。
创建项目
初始化项目
复制代码 代码如下:mvn archetype:generate -DgroupId=com.edurt.ssi -DartifactId=springboot-scala-integration -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=1.0.0 -DinteractiveMode=false
修改pom.xml增加java和scala的支持
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.edurt.ssi.service.UserServiceimport org.junit.jupiter.api.Testimport org.springframework.beans.factory.annotation.Autowiredimport org.springframework.boot.test.context.SpringBootTestimport org.springframework.data.domain.PageRequest@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)class UserServiceTest @Autowired()( private val userService: UserService) { @Test def `get all`() { println(">> Assert blog page title, content and status code") val entity = this.userService.getAll(PageRequest.of(0, 1)) print(entity.getTotalPages) }}
源码地址:GitHub
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。