run scala with java use spring mvc(java项目加入 scala)

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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值