本站网址
www.kjyfx.com

『Java』Spring Boot项目yml配置文件及相关pom依赖

一.yml配置文件

根据需求自行选择配置

 

1、关于Server

 

#server配置
server:
  port: 81   #配置访问端口
  servlet:
    context-path: / #配置项目访问路径,/代表端口后只需加RequestMapping映射路径即可访问
  tomcat:
    max-threads: 1000 #最大线程数

 

2、关于Spring

#spring配置
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource   #引入druid数据源
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true #数据库
    username: root
    password: root
  thymeleaf:                                              #配置模板引擎,基于html静态页面时使用
    prefix: classpath:/templates/pages/
    suffix: .html
  mvc:                                                    #定义springmvc视图解析器,基于JSP动态网页使用
    view:
      prefix: /WEB-INF/views/                             #/默认代表根目录 src/main/webapp
      suffix: .jsp
  aop:
    proxy-target-class: false                             #类的代理将不起作用
  data:                                                   #整合solr全文索引
    solr:
      host: http://192.168.161.134:8983/solr/pd
  rabbitmq:                                               #整合rabbitMQ队列
    host: 192.168.161.135
    port: 5672
    virtualHost: /pd
    username: admin
    password: admin
    listener:                                             #手动确认
      simple:         
        acknowledge-mode: manual 

 

3、关于Mybatis或Mybatis-plus

#mybatis配置
mybatis-plus: #mabatis同理
  configuration:
    default-statement-timeout: 30              #默认连接超时时长
    map-underscore-to-camel-case: true         #开启驼峰映射
  mapper-locations:
  - classpath:/mappers/*.xml                   #mapper.xml文件路径

 

4、引入日志

#引入日志
logging:
  level:
    com.kjyfx: debug

 

5.1、dubbo框架————消费者

#dubbo集群配置——————消费者端配置 
dubbo:
  scan:
    basePackages: com.kjyfx    #配置包扫描
  application:
    name: consumer-web   #服务名称必须定义
  registry:
    address: zookeeper://192.168.161.132:2181?backup=192.168.161.132:2182,192.168.161.132:2183 #注册中心地址及端口

 

5.2、dubbo框架————生产者

dubbo:
  scan:
    basePackages: com.jt #配置包扫描
  application: #服务名称必须定义
    name: provider-order
  registry: #注册中心
    address: zookeeper://192.168.38.128:2181?backup=192.168.38.128:2182,192.168.38.128:2183 #?backup=192.168.126.176:2182,192.168.126.176:2183
  protocol:
   name: dubbo #zookeeper节点名称
  port: 20882 #RPC通信 dubbo内部通信端口,每个生产者的端口必须不同

 

二、pom.xml依赖及相关插件(根据需求添加)

<!--springBoot动态的引入springMVC全部的配置 -->
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-web</artifactId> 
</dependency>

<!-- 引入aop支持 -->
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<!--引入测试类 -->
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-test</artifactId> 
    <scope>test</scope> 
</dependency>

<!--添加属性注入依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-configuration-processor</artifactId> 
    <optional>true</optional> 
</dependency>

<!--支持热部署 -->
<dependency> 
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>

<!--引入插件lombok 自动的set/get/构造方法插件 -->
<dependency> 
    <groupId>org.projectlombok</groupId> 
    <artifactId>lombok</artifactId> 
</dependency>

<!--引入数据库驱动 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.32</version> 
    <scope>runtime</scope> 
</dependency>

<!--引入druid数据源 -->
<dependency> 
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId> 
    <version>1.1.12</version> 
</dependency>

<!--spring整合mybatis-plus --> 
<dependency> 
    <groupId>com.baomidou</groupId> 
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.0.6</version> 
</dependency>

<!--spring整合redis 
    1.jedis SSM springBoot 底层整合方式 了解整合具体过程.
    2.redisTemplate  高级API.springBoot内部 实现了整合. 直接使用API即可. -->
<dependency> 
    <groupId>redis.clients</groupId> 
    <artifactId>jedis</artifactId>
</dependency>
<dependency> 
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId> 
</dependency>

<!--springBoot整合JSP添加依赖 -->
<dependency>
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
</dependency>

<!--使jsp页面生效 -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId> 
    <artifactId>tomcat-embed-jasper</artifactId> 
</dependency>

<!--jstl依赖 --> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jstl</artifactId> 
</dependency>

<!--添加httpClient jar包 -->
<dependency> 
    <groupId>org.apache.httpcomponents</groupId> 
    <artifactId>httpclient</artifactId> 
</dependency>


<!--引入dubbo配置 -->
<dependency>
    <groupId>com.alibaba.boot</groupId> 
    <artifactId>dubbo-spring-boot-starter</artifactId> 
    <version>0.2.0</version> 
</dependency>

<!--添加Quartz的支持 -->
<dependency>
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-quartz</artifactId> 
</dependency>

<!--引入swagger插件 -->
<dependency>
    <groupId>io.springfox</groupId> 
    <artifactId>springfox-swagger2</artifactId> 
    <version>2.7.0</version>
</dependency>

<!--引入swaggerUI包 -->
<dependency>
    <groupId>io.springfox</groupId> 
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version> 
</dependency>

<!--引入RabbitMQ -->
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-amqp</artifactId>
</dependency>


<!--跳过测试类打包插件 -->
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip> 
            </configuration>
        </plugin>
        <plugin> 
            <groupId>org.springframework.boot</groupId> 
            <artifactId>spring-boot-maven-plugin</artifactId> 
        </plugin>
    </plugins>
</build>

 

赞(4) 打赏
未经允许不得转载:所有资源由个人搜集整理自互联网,仅用于学习交流使用,请勿用于其他商业用途。如有侵权,请联系2448941602@qq.com删除科技云分享 » 『Java』Spring Boot项目yml配置文件及相关pom依赖
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

更多资源,尽在微信公众号【科技云分享】

关注公众号加入Q群

我叫科技云,感谢您的支持~

支付宝扫一扫打赏

微信扫一扫打赏