從零開始搭建Springboot+Driud+Mybatis+Mysql+Presto框架搭建,代碼,視頻(一)

SpringBoot作爲當下最流行微服務框架,已經成爲許多公司業務處理的一部分。本人基於公司業務,簡單整理了下自己在搭建框架過程遇到的問題和心得,用於解決其他小夥伴在面臨相同問題時,能快速的上手和使用。視頻,代碼和文檔在文章末尾有連接。

主要框架及組件:Springboot+Dubbo+Driud+Mybatis+Mysql+Presto+Redis

場景:公司業務並不是很複雜,主要是一些Sql的查詢,統計,分頁,分組和排序的處理。但是隨着時間推移,數據不斷積累,RDS中數據的增量越來越大。單表數據最大的達到了32億條記錄,多張億級的大表佔用將近10TB的存儲,嚴重影響了前端的查詢效率,而且佔用很大的資源。

該篇是整個框架搭建的第一篇,主要記錄idea搭建Springboot框架過程

idea激活下載鏈接:http://idea.94goo.com

idea創建一個maven項目(默認大家已經安裝好JDK並配置了環境變量和maven等工具)

配置阿里雲遠程倉庫

選擇自己安裝的maven地址和指定本地的maven倉庫路徑,同時,建議將setting.xml文件修改爲阿里的遠程倉庫。將以下代碼放到<mirrors></mirrors>

<mirror>  
  <id>alimaven</id>  
  <name>aliyun maven</name>  
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>          
</mirror>

添加開發需要的jar包到pom中,首先,添加parent標籤,並引入spring-boot-starter-parent,方便對包版本的統一管理。

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

然後,引入必須的開發依賴包,在<dependencies></dependencies>標籤中,加入依賴,如下:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

創建包結構和配置文件

創建application,common,modules包,分別用於後面放啓動應用入口,工具管理和模塊管理。如圖:

修改resources目錄爲資源目錄,右鍵File --> Project Structure,

Apply應用,ok,退出即可。

添加啓動程序入口Application.java。

註解說明:

@Configuration

@SpringBootApplication

@ComponentScan("com.relyun.bigdata")

package com.relyun.bigdata.application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;


import java.util.TimeZone;

/**
 * 啓動方法
 */
@Configuration
@SpringBootApplication
@ComponentScan("com.relyun.bigdata")
public class Application {
    public static void main(String[] args) {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));  //設置時區
        SpringApplication.run(Application.class, args);
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章