Springboot中使用Scala开发

新建maven工程,添加pom依賴:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>SpringBootDemo</groupId>
  <artifactId>SpringBoot</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <scala-version>2.10.4</scala-version>
    <lucene-version>5.5.0</lucene-version>
    <cassandra-driver-version>3.1.4</cassandra-driver-version>
    <apache-curator-version>2.11.1</apache-curator-version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
  </parent>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.fasterxml.uuid</groupId>
        <artifactId>java-uuid-generator</artifactId>
        <version>3.1.4</version>
      </dependency>
      <dependency>
        <groupId>io.spring.platform</groupId>
        <artifactId>platform-bom</artifactId>
        <version>Brussels-SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>${cassandra-driver-version}</version>
      </dependency>
      <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-mapping</artifactId>
        <version>${cassandra-driver-version}</version>
      </dependency>
      <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.3</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <!--spring boot-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala-version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-reflect</artifactId>
      <version>${scala-version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang.modules</groupId>
      <artifactId>scala-xml_2.11</artifactId>
      <version>1.0.6</version>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-client</artifactId>
      <version>${apache-curator-version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-framework</artifactId>
      <version>${apache-curator-version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-recipes</artifactId>
      <version>${apache-curator-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.uuid</groupId>
      <artifactId>java-uuid-generator</artifactId>
    </dependency>
    <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-mapping</artifactId>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
    </dependency>

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>19.0</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
      <scope>true</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <fork>true</fork>
        </configuration>
      </plugin>

      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.2.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

一个简单例子:

package com.demo

import org.springframework.web.bind.annotation.{RequestMapping, RestController}

@RestController
//@RequestMapping(Array("/index"))
class sadsa  {

//  @RequestMapping(Array("", "/"))
  @RequestMapping(Array("/index"))
  def index(): String = {
    "hello SpringBoot"
  }

  @RequestMapping(Array("/index1"))
  def index1(): String = {
    "hello SpringBoot"
  }
}
package com.demo

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter

@SpringBootApplication(scanBasePackages = Array("com.demo"))
class AppConf extends WebMvcConfigurerAdapter {

}
object Runner {
  def main(args: Array[String]): Unit = {
    SpringApplication.run(classOf[AppConf])
  }
}

原文地址:https://www.cnblogs.com/kxgdby/p/8985202.html

时间: 2024-08-02 03:40:45

Springboot中使用Scala开发的相关文章

Eclipse中构建scala开发环境的步骤

Eclipse是一款非常使用的开发工具,熟悉它的童鞋应该都知道,它不仅是最常用的android开发工具,还是最常用的Java开发工具.既然eclipse如此重要,本文小编就和大家一起来扒一扒在eclipse中构建scala开发环境的相关知识,有兴趣的童鞋可以一起来看看. 1.scala是什么 其实,scala是 一种语法,类似Java,而sbt是 一个构建工具,类似maven,gradle,ant等.在eclipse中只有scala开发环境的插件,可以构建scala project,但是没有sb

springboot中的AOP开发

三步: 1.引入springboot-boot-start-aop jar包 <!--springboot与aop集成jar包--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> 2.开发切面 两个主要的注解:@Configurat

Intellij IDEA 14.1.4 Scala开发环境搭建

主要内容 Intellij IDEA开发环境简介 Intellij IDEA Scala开发环境搭建 Intellij IDEA常见问题及解决方案 Intellij IDEA常用快捷键 1. Intellij IDEA开发环境简介 具体介绍请参见:http://baike.baidu.com/link?url=SBY93H3SPkmcmIOmZ8H60O1k4iVLgOmdqoKdGp9xHtU-Pbdsq2cpn75ZPZPWAJxeUlwr0ravraQzOckh777beq Intelli

构造Scala开发环境并创建ApiDemos示例项目

从2011年开始写Android ApiDemos 以来,Android的版本也更新了很多,目前的版本已经是4.04.ApiDemos中的例子也增加了不少,有必要更新Android ApiDemo示例解析系列文章(当然之前的文章还是有用的,依然可以作为参考).为了不重复之前的内容,我们准备使用Scala语言开发Android应用,随着例子的逐步解析,我们会把ApiDemos的例子的代码依次修改为Scala代码,并使用Robujuice 来注入View,关于Scala编程可以参考博客scala开发

SpringBoot中使用Spring Data Jpa 实现简单的动态查询的两种方法

首先谢谢大佬的简书文章:http://www.jianshu.com/p/45ad65690e33# 这篇文章中讲的是spring中使用spring data jpa,使用了xml配置文件.我现在使用的是spring boot ,没有了xml文件配置就方便多了.我同样尝试了两种方式,也都是简单的查询,需要更复杂的查询,还需要我研究研究.往下看,需要先配置springboot的开发环境,需要大致了解springboot,这里可以看下面两篇文章: springboot 项目新建 springboot

Scala学习1————scala开发环境搭建(windows 10)

Scala开发环境搭建 先讲几点我学习scala的目的或者原因吧: JVM在企业中的霸主地位,Scala也是JVM上的语言,很有可能未来会从Java过度到Scala也不是不可能. 先进的函数式编程和面向对象的结合. 我个人对大数据方面的知识特别感兴趣,发现Kafka和Spark的源码都是scala编写的,而如果我想深入的学习,学习源码可能要用到scala. Spark的生产环境使用Java或者Scala编程似乎是主流,然而开发Spark程序的话使用Java没有使用Scala开发相率高. Scal

Scala开发环境搭建

0.简介 Scala(发音为 /?skɑ?l?, ?ske?l?/)是一种多范式的编程语言,设计初衷是要集成面向对象编程和函数式编程的各种特性. Scala运行于Java平台(Java虚拟机),并兼容现有的Java程序.Scala的编译模型(独立编译,动态类加载)与Java和C#一样,所以Scala代码可以调用Java类库(对于.NET实现则可调用.NET类库). Scala包包括编译器和类库,以BSD许可证发布. 1.下载必须的软件 JDK Scala是基于JVM的,所以必须要下载JDK,链接

scala开发环境

1. Intellij IDEA Scala开发环境搭建 Intellij IDEA 15.0.3 默认配置里面没有Scala插件,需要手动安装,在Intellij IDEA 15.0.3 第一次运行时选择configure plugins,选择默认后在软件主界面去配置,但是本人测试发现,这种设置方式经常会因为网络问题配置失败,建议直接到 http://www.jetbrains.net/confluence/display/SCA/Scala+Plugin+for+IntelliJ+IDEA,

使用scala开发spark入门总结

使用scala开发spark入门总结 一.spark简单介绍 关于spark的介绍网上有很多,可以自行百度和google,这里只做简单介绍.推荐简单介绍连接:http://blog.jobbole.com/89446/ 1.    spark是什么? Spark是UC Berkeley AMP lab (加州大学伯克利分校的AMP实验室)所开源的类Hadoop MapReduce的通用并行框架.一般配合hadoop使用,可以增强hadoop的计算性能. 2.    Spark的优点有哪些? Sp