zoukankan      html  css  js  c++  java
  • 统一元数据管理 【SpringBoot+Java+Scala】

    项目开发流程

    统一元数据管理的重要性
    目前集群上总的数据量是多少?
    集群上的每张表有几个分区?每个分区所占大小?每个分区有多少记录?
    每张表有哪些字段?哪些字段使用比较热?热表?热字段?
    表之间的血缘关系?表可能是从其余表转换来的!

    正式开始

    • 步骤一:新建一个SpringBoot项目,先添加web依赖就可以了

    • 步骤二:得到的是一个maven项目,在pom文件中添加如下依赖,目的是确保能支持数据库访问层,即dao层的功能

         <!--添加Data的依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
    
            <!--添加MySQL驱动-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.47</version>
            </dependency>
            <!--添加lombok 插件 ,可选-->
             <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
    
    • 步骤三:到这里,其实正常使用Java代码就是可以开发起来的,但是我们想要部分功能使用Scala代码开发。
      就先得引入依赖,还有就是scala-plugin插件。

    scala依赖如下:

     <scala.version>2.11.8</scala.version>
    
         <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
                <version>${scala.version}</version>
         </dependency>
    

    添加Scala的plugin:

     <!--添加Scala的plugin-->
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.1</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>
                        <recompileMode>incremental</recompileMode>
                        <scalaVersion>${scala.version}</scalaVersion>
                        <args>
                            <arg>-deprecation</arg>
                        </args>
                        <jvmArgs>
                            <jvmArg>-Xms64m</jvmArg>
                            <jvmArg>-Xmx1024m</jvmArg>
                        </jvmArgs>
                    </configuration>
                </plugin>
    
    • 步骤四:到这里,我们就成功构建起开发环境
      IDEA+SprigBoot+Spring Data JPA + Java + scala 混合开发的模式
      简单说一下,混编的好处。
      1.好处一:对于我们历史项目中写好的许多Java 工具类,可以直接调用
      2.好处二:其实,对于整个市场来说,Java的第三方工具类及其支持肯定是好很多的。这样我们的Scala项目在集成Java之后就很舒服啦.其实还是类似第一点

    简单总结:

    1.scala 的更多用法

          
           @RequestMapping(value = Array("/table"),method = Array(RequestMethod.POST))
             说明:这个value的类型需要是 Array[String],包括method也是
      
           class MetaTableController @Autowired()(metaTableService: MetaTableService) = {???}
             说明:注入的方式比较不一样
            
           trait MetaTableRepository extends CrudRepository[MetaTable, Integer] {}
             说明:定义接口使用trait 关键字,参数类型使用中括号[] ,不同于Java的<>尖括号
                  接口实现同样使用extends 关键字,实现多个可以使用with进行连接 ,with Serializable
    
          var id:Integer = _ javaBean实体类定义
    
    
    1. spring data jpa 用法
            导入starter-jar + mysql 依赖
            spring.datasource.driver-class-name=com.mysql.jdbc.Driver
            spring.datasource.url=jdbc:mysql://xxx:3306/bootscala?useUnicode=true&characterEncoding=UTF-8&useSSL=false
            spring.datasource.username=root
            spring.datasource.password=123456
            #######  添加jps相关配置
            spring.jpa.hibernate.ddl-auto=update // 不用创建表,直接启动即可
            spring.jpa.database=mysql
            #######  实体类中
            @Entity
            @Table
            @Id
            @GeneratedValue
            #######  数据库访问层
            public interface MetaDatabaseRepository extends CrudRepository<MetaDatabase,Integer> {}
    
    1. springboot 测试用例简单编写
      @RunWith(SpringRunner.class)
      @SpringBootTest
      @Test

      更多可以去看看junit 相关知识

    项目位置:https://github.com/liuge36/boot2spark-project ,欢迎Star~
    好的,到这里就结束了,有问题可以留言交流~

  • 相关阅读:
    c# 时间操作
    JAVA file文件操作
    HttpServletRequest 转换成MultipartHttpServletRequest
    【日常笔记】java spring 注解读取文件
    【日常笔记】mybatis 处理 in 语句的使用
    购物车小程序
    Python中的r+和a+
    markdown基本语法
    markdown箭头的处理
    markdown中如何插入公式
  • 原文地址:https://www.cnblogs.com/liuge36/p/12614720.html
Copyright © 2011-2022 走看看