【SpringBoot】SpringBoot项目常用依赖及其配置

【SpringBoot】SpringBoot项目常用依赖及其配置

文章目录

  • 【SpringBoot】SpringBoot项目常用依赖及其配置
    • 一 基本设置
      • 1. Maven常用依赖
      • 2. yml基本配置
    • 二 拓展配置
      • 1. Redis依赖及配置
        • 1.1 Redis依赖
        • 1.2 Redis配置
      • 2. MongoDB依赖及配置
        • 2.1 MongoDB依赖
        • 2.2 MongoDB配置
      • 3. JavaMail依赖及配置
        • 3.1 JavaMail依赖
        • 3.2 JavaMail配置
      • 4. 七牛云依赖及配置
        • 4.1 七牛云依赖
        • 4.2 七牛云配置
    • 配置自定义,无固定写法。
      • 5. RabbitMQ依赖及配置
        • 5.1 RabbitMQ依赖
        • 5.2 RabbitMQ配置

一 基本设置

1. Maven常用依赖

数据库为mysql,连接池为druid,orm为mp。版本根据需要而变化

  <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <scope>runtimescope>
        dependency>
        
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
        
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-boot-starterartifactId>
            <version>3.5.2version>
        dependency>
        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druid-spring-boot-starterartifactId>
            <version>1.2.11version>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombokgroupId>
                            <artifactId>lombokartifactId>
                        exclude>
                    excludes>
                configuration>
            plugin>
        plugins>
    build>

2. yml基本配置

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/clinic?useSSL=false&characterEncoding=utf-8
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
  
mybatis-plus:
  configuration:
    #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
    map-underscore-to-camel-case: true
    # 日志
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      logic-delete-field: delFlag
      logic-delete-value: 1
      logic-not-delete-value: 0
      id-type: auto
  mapper-locations: classpath*:/mapper/**/*.xml

二 拓展配置

以下涉及的中间件及数据库只考虑单机配置,不做集群配置。

1. Redis依赖及配置

1.1 Redis依赖

    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-data-redisartifactId>
    dependency>

1.2 Redis配置

spring:
  redis:
    host: localhost
    port: 6379
    database: 0

2. MongoDB依赖及配置

2.1 MongoDB依赖

 <dependency>
     <groupId>org.springframework.bootgroupId>
     <artifactId>spring-boot-starter-data-mongodbartifactId>
 dependency>

2.2 MongoDB配置

spring:
  data:
    mongodb:
      host: localhost
      database: articledb
      port: 27017
      #也可以使用uri连接
      #uri: mongodb://127.0.0.1:27017/articledb

3. JavaMail依赖及配置

3.1 JavaMail依赖

  <dependency>
      <groupId>org.springframework.bootgroupId>
      <artifactId>spring-boot-starter-mailartifactId>
  dependency>

3.2 JavaMail配置

spring:
  mail:
    host: smtp.qq.com
    username: [email protected]
    password: xxx

4. 七牛云依赖及配置

4.1 七牛云依赖

   <dependency>
     <groupId>com.qiniugroupId>
     <artifactId>qiniu-java-sdkartifactId>
     <version>[7.7.0, 7.7.99]version>
   dependency>

4.2 七牛云配置

配置自定义,无固定写法。

5. RabbitMQ依赖及配置

5.1 RabbitMQ依赖


<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-amqpartifactId>
dependency>

5.2 RabbitMQ配置

spring:
  rabbitmq:
    # 主机名
    host: 192.168.150.101 
    # 端口
    port: 5672 
    # 虚拟主机
    virtual-host: / 
    # 用户名
    username: root 
    # 密码
    password: 123456 

想到什么了再续。。。

你可能感兴趣的:(Spring,spring,boot,java,mybatis,spring,java-ee)