1. pom.xml 增加scala lib 和编译配置
<!--jdk1.8版本加入或者更高版本的 scala-->
<properties>
<scala-version>2.10.4</scala-version>
</properties>
<!-- jdk1.7加入 -->
<properties>
<scala-version>2.9.3-RC2</scala-version>
</properties>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
</dependency>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>compile-scala</id>
<phase>compile</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile-scala</id>
<phase>test-compile</phase>
<goals>
<goal>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala-version}</scalaVersion>
</configuration>
</plugin>
</plugins>
2. 增加 controller 测试类
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{ResponseBody, RequestMethod, RequestMapping}
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import com.nfsq.customer.sync.task.CustomerIncrementSyncTask
import org.springframework.beans.factory.annotation.Autowired
import scala.collection.JavaConverters._
/**
* curl http://127.0.0.1:8080/nfsq_customer_sync/scala/sayHello.json
*/
@Controller
@RequestMapping(value = Array("/scala"))
class ScalaJobController {
/**
* sacla say hello demo
* @return hello, scala
*/
@RequestMapping(value = Array("/sayHello.json"), method = Array(RequestMethod.GET))
@ResponseBody
def sayHello(): String = {
println("hello scala")
"hello, scala"
}
}
有任何问题欢迎一起交流 370798490@qq.com
公司博文: http://it.nfsq.com.cn/index.php/2016/04/15/run-scala-with-java-use-spring-mvc/