📐 Spring环境配置
# 约定大于配置
Forest是基于约定大于配置的理念进行设计的,如果您已经添加好了Forest Spring环境相关依赖,只要进行些简单的配置即可使用
# 配置 XML SCEHEMA
打开spring的上下文配置文件,在beans开头定义的属性中加入Forest的Schema
xmlns:forest="http://forest.dtflyx.com/schema/forest"
   ...
xsi:schemaLocation=" ...
http://forest.dtflyx.com/schema/forest
http://forest.dtflyx.com/schema/forest/forest-spring.xsd
..."
 1
2
3
4
5
6
2
3
4
5
6
加入完成后类似如下效果
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:forest="http://forest.dtflyx.com/schema/forest"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://forest.dtflyx.com/schema/forest
       http://forest.dtflyx.com/schema/forest/forest-spring.xsd">
    
   ...
</beans>
 1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 添加Forest基本配置的定义
<!-- Forest 全局配置 -->
<!-- maxConnections 每个路由的最大连接数 -->
<!-- connectTimeout 连接超时时间,单位为毫秒 -->
<!-- readTimeout 数据读取超时时间,单位为毫秒 -->
<forest:configuration
        id="configuration"
        maxConnections="500"
        connectTimeout="10000"
        readTimeout="3000">
   
    <!-- 定义 Forest 客户端接口所在的包名 -->
    <!-- 扫描 base-package 属性定义包,然后会将该包名下符合条件的接口进行动态代理并注入到 Spring 的上下文中 -->
    <forest:scan configuration="configuration" base-package="com.yoursite.client"/>
   
</forest:configuration>
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 详细配置
Forest的详细配置说明,请参见《Spring环境配置项》
帮助我们改善此文档  (opens new window)
  上次更新: 2024/12/26, 12:59:11