最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot環(huán)境配置知識總結(jié)

 更新時間:2021年05月24日 10:10:17   作者:gaoz666  
今天帶大家了解SpringBoot環(huán)境配置的相關(guān)知識,文中有非常詳細的代碼示例,對正在學習java的小伙伴們有很好地幫助,需要的朋友可以參考下

一、pom文件配置

<!-- SpringBoot的父級依賴。只有設置了parent標簽,項目才是SpringBoot項目  -->
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.2.2.RELEASE</version>
</parent>

<dependencies>
   <!-- web啟動器,加載web環(huán)境所需要的依賴 -->
   <dependency>
   		<groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- mybatis 集成 -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.1</version>
    </dependency>
    <!-- springboot 分頁插件 -->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.13</version>
    </dependency>
    <!-- mysql 驅(qū)動 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- c3p0 數(shù)據(jù)源 -->
    <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.5.5</version>
    </dependency>
    <!-- Freemarker Starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
    <!-- Thymeleaf Starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- JavaMail -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <!-- AOP -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <!-- Log -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <!-- tomcat -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- 為使用StringUtils工具類 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
    <!-- API文檔 -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    <!-- DevTools 的坐標 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <!--當前這個項目被繼承之后,這個不向下傳遞-->
        <optional>true</optional>	
    </dependency>
    <!-- SpringBoot單元測試 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <!-- Ehcache -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
    </dependency>
    
</dependencies>

<!-- SpringBoot項目的打包插件 -->
<build>
    <finalName>springboot</finalName>
	<plugins>
  	<plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <fork>true</fork><!-- 如果沒有該配置,熱部署的devtools不生效 -->
        </configuration>
    </plugin>
  </plugins>
</build>

相關(guān)starter系列坐標參考:

名稱 描述
spring-boot-starter 核心Spring Boot starter,包括自動配置支持,日志和YAML
spring-boot-starter-actuator 生產(chǎn)準備的特性,用于幫我們監(jiān)控和管理應用
spring-boot-starter-amqp 對”高級消息隊列協(xié)議”的支持,通過spring-rabbit實現(xiàn)
spring-boot-starter-aop 對面向切面編程的支持,包括spring-aop和AspectJ
spring-boot-starter-batch 對Spring Batch的支持,包括HSQLDB數(shù)據(jù)庫
spring-boot-starter-cloud-connectors 對Spring Cloud Connectors的支持,簡化在云平臺下(例如,Cloud Foundry 和Heroku)服務的連接
spring-boot-starter-data-elasticsearch 對Elasticsearch搜索和分析引擎的支持,包括spring-data-elasticsearch
spring-boot-starter-data-gemfire 對GemFire分布式數(shù)據(jù)存儲的支持,包括spring-data-gemfire
spring-boot-starter-data-jpa 對”Java持久化API”的支持,包括spring-data-jpa,spring-orm和Hibernate
spring-boot-starter-data-mongodb 對MongoDB NOSQL數(shù)據(jù)庫的支持,包括spring-data-mongodb
spring-boot-starter-data-rest 對通過REST暴露Spring Data倉庫的支持,通過spring-data-rest-webmvc實現(xiàn)
spring-boot-starter-data-solr 對Apache Solr搜索平臺的支持,包括spring-data-solr
spring-boot-starter-freemarker 對FreeMarker模板引擎的支持
spring-boot-starter-groovy-templates 對Groovy模板引擎的支持
spring-boot-starter-hateoas 對基于HATEOAS的RESTful服務的支持,通過spring-hateoas實現(xiàn)
spring-boot-starter-hornetq 對”Java消息服務API”的支持,通過HornetQ實現(xiàn)
spring-boot-starter-integration 對普通spring-integration模塊的支持
spring-boot-starter-jdbc 對JDBC數(shù)據(jù)庫的支持
spring-boot-starter-jersey 對Jersey RESTful Web服務框架的支持
spring-boot-starter-jta-atomikos 對JTA分布式事務的支持,通過Atomikos實現(xiàn)
spring-boot-starter-jta-bitronix 對JTA分布式事務的支持,通過Bitronix實現(xiàn)
spring-boot-starter-mail 對javax.mail的支持
spring-boot-starter-mobile 對spring-mobile的支持
spring-boot-starter-mustache 對Mustache模板引擎的支持
spring-boot-starter-redis 對REDIS鍵值數(shù)據(jù)存儲的支持,包括spring-redis
spring-boot-starter-security 對spring-security的支持
spring-boot-starter-social-facebook 對spring-social-facebook的支持
spring-boot-starter-social-linkedin 對spring-social-linkedin的支持
spring-boot-starter-social-twitter 對spring-social-twitter的支持
spring-boot-starter-test 對常用測試依賴的支持,包括JUnit, Hamcrest和Mockito,還有spring-test模塊
spring-boot-starter-thymeleaf 對Thymeleaf模板引擎的支持,包括和Spring的集成
spring-boot-starter-velocity 對Velocity模板引擎的支持
spring-boot-starter-web 對全棧web開發(fā)的支持, 包括Tomcat和spring-webmvc
spring-boot-starter-websocket 對WebSocket開發(fā)的支持
spring-boot-starter-ws 對Spring Web服務的支持

二、yml文件配置

yml文件放在resources目錄下

## 端口號  上下文路徑
server:
  port: 8989
  servlet:
    context-path: /mvc

## 數(shù)據(jù)源配置
spring:
  datasource:
    type: com.mchange.v2.c3p0.ComboPooledDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/hr
    username: root
    password: root
    
  freemarker:
    suffix: .ftl
    content-type: text/html  #響應格式
    charset: UTF-8
    template-loader-path: classpath:/views/
    
  ## 熱部署配置
  devtools:
    restart:
      enabled: true
      # 設置重啟的目錄,添加目錄的文件需要restart
      additional-paths: src/main/java
      # 解決項目自動重新編譯后接口報404的問題
      poll-interval: 3000
      quiet-period: 1000
      
  ## Ehcache緩存配置
  cache:
    ehcache:
      config: classpath:ehcache.xml
    
## mybatis 配置
mybatis:
  #映射文件的存放路徑
  mapper-locations: classpath:/mappers/*.xml
  type-aliases-package: com.xxxx.springboot.po
  configuration:
    ## 下劃線轉(zhuǎn)駝峰配置
    map-underscore-to-camel-case: true

## pageHelper
pagehelper:
  helper-dialect: mysql

## 顯示dao 執(zhí)行sql語句
logging:
  level:
    com:
      xxxx:
        dao: debug

三、SQL映射文件配置

sql映射文件路徑在"resources/mappers/"下

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xxxx.dao.UserMapper">
    
</mapper>

四、ehcahe.xml 文件

配置在resources下

<ehcache name="mycache">
  	<!-- 
		如果不使用磁盤存儲,只需要將diskStore注釋掉即可;
		如果使用,需要在ehcache.xml文件中的ehcahce元素下的定義一個diskStore元素并指定其path屬性。 
	-->
    <diskStore path="C:\java\cache"/>
    <!--
        name:緩存名稱。
        maxElementsInMemory:緩存最大數(shù)目
        maxElementsOnDisk:硬盤最大緩存?zhèn)€數(shù)。
        eternal:對象是否永久有效,一但設置了,timeout將不起作用。
        overflowToDisk:是否保存到磁盤,當系統(tǒng)宕機時
        timeToIdleSeconds:設置對象在失效前的允許閑置時間(單位:秒)。
        	僅當eternal=false對象不是永久有效時使用,可選屬性,默認值是0,表示可閑置時間無窮大。
        timeToLiveSeconds:設置對象在失效前允許存活時間(單位:秒)。
            最大時間介于創(chuàng)建時間和失效時間之間。
			僅當eternal=false對象不是永久有效時使用,默認是0,也就是對象存活時間無窮大。
        diskPersistent:是否緩存虛擬機重啟期數(shù)據(jù) 
			Whether the disk store persists between restarts of the Virtual Machine. 			 The default value is false.
        diskSpoolBufferSizeMB:這個參數(shù)設置DiskStore(磁盤緩存)的緩存區(qū)大小。
			默認是30MB。每個Cache都應該有自己的一個緩沖區(qū)。
        diskExpiryThreadIntervalSeconds:磁盤失效線程運行時間間隔,默認是120秒。
        memoryStoreEvictionPolicy:當達到maxElementsInMemory限制時,會根據(jù)指定的策略去清理內(nèi)存
             默認策略是LRU(最近最少使用)。你可以設置為FIFO(先進先出)或是LFU(較少使用)。
        clearOnFlush:內(nèi)存數(shù)量最大時是否清除。
        memoryStoreEvictionPolicy:
			可選策略有:
				LRU(最近最少使用,默認策略)
					Less Frequently Used,就是例子中使用的策略,就是一直以來最少被使用的。
				FIFO(先進先出)
					first in first out,這個是大家最熟的,先進先出。
				LFU(最少訪問次數(shù))
					Least Recently Used,最近最少使用的。
					緩存的元素有一個時間戳,當緩存容量滿了,而又需要騰出地方來緩存新的元素的時候,
					那么現(xiàn)有緩存元素中時間戳離當前時間最遠的元素將被清出緩存。
        -->
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            maxElementsOnDisk="10000000"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU">
    </defaultCache>

    <cache
            name="users"
            eternal="false"
            maxElementsInMemory="100"
            overflowToDisk="false"
            diskPersistent="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="300"
            memoryStoreEvictionPolicy="LRU"/>
</ehcache>

到此這篇關(guān)于SpringBoot環(huán)境配置知識總結(jié)的文章就介紹到這了,更多相關(guān)SpringBoot環(huán)境配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java正則替換手機號代碼實例

    Java正則替換手機號代碼實例

    本文的主要內(nèi)容是Java語言中正則表達式替換手機號的第4到第7位,實現(xiàn)方法十分簡單,同時涉及了一些正則表達式的相關(guān)用法,需要的朋友可以參考下。
    2017-09-09
  • Java異步線程中的CompletableFuture與@Async詳解

    Java異步線程中的CompletableFuture與@Async詳解

    這篇文章主要介紹了Java異步線程中的CompletableFuture與@Async詳解,CompletableFuture是java中提供的一個異步執(zhí)行類,@Async是Spring提供的異步執(zhí)行方法,當調(diào)用方法單獨開啟一個線程進行調(diào)用,需要的朋友可以參考下
    2024-01-01
  • 詳解Java8中Optional的常見用法

    詳解Java8中Optional的常見用法

    Opitonal是java8引入的一個新類,目的是為了解決空指針異常問題。本文將通過示例為大家詳細講講Optional的常見用法,需要的可以參考一下
    2022-09-09
  • springboot整合mybatis實現(xiàn)數(shù)據(jù)庫的更新批處理方式

    springboot整合mybatis實現(xiàn)數(shù)據(jù)庫的更新批處理方式

    這篇文章主要介紹了springboot整合mybatis實現(xiàn)數(shù)據(jù)庫的更新批處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Spring中FactoryBean的高級用法實戰(zhàn)教程

    Spring中FactoryBean的高級用法實戰(zhàn)教程

    FactoryBean是Spring框架的高級特性,允許自定義對象的創(chuàng)建過程,適用于復雜初始化邏輯,本文給大家介紹Spring中FactoryBean的高級用法實戰(zhàn),感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • spring boot 配置HTTPS代碼實例

    spring boot 配置HTTPS代碼實例

    這篇文章主要介紹了spring boot 配置HTTPS代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11
  • SpringBoot實現(xiàn)阿里云短信發(fā)送的示例代碼

    SpringBoot實現(xiàn)阿里云短信發(fā)送的示例代碼

    這篇文章主要為大家介紹了如何利用SpringBoot實現(xiàn)阿里云短信發(fā)送,文中的示例代碼講解詳細,對我們學習或工作有一定幫助,需要的可以參考一下
    2022-04-04
  • java使用wait和notify實現(xiàn)線程通信

    java使用wait和notify實現(xiàn)線程通信

    這篇文章主要為大家詳細介紹了java如何使用wait和notify實現(xiàn)線程之間通信,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-10-10
  • java FileWriter 追加文件及文件改名方式

    java FileWriter 追加文件及文件改名方式

    這篇文章主要介紹了java FileWriter 追加文件及文件改名的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • SpringMVC之返回JSON的三種方式

    SpringMVC之返回JSON的三種方式

    現(xiàn)在都是前后端分離了,后端只需要跟前端提供restful接口,所有接口都返回json格式數(shù)據(jù)即可,SpringMVC通常有3種方式向前端輸出json格式數(shù)據(jù),下面我們就來了解一下
    2023-06-06

最新評論

黄梅县| 云和县| 从化市| 天气| 绥棱县| 徐汇区| 昌平区| 黎川县| 扶余县| 江达县| 江山市| 鲁山县| 南投县| 滨州市| 呈贡县| 介休市| 昌邑市| 聂拉木县| 思南县| 凤凰县| 马边| 泰安市| 凭祥市| 社会| 扬中市| 常宁市| 吴旗县| 杨浦区| 锡林浩特市| 长阳| 奉化市| 诸城市| 达拉特旗| 武穴市| 手机| 贺兰县| 清河县| 库尔勒市| 高清| 阿图什市| 广安市|