上一篇我们介绍《构建dubbo分布式平台-maven构建ant-parent项目》,框架使用maven进行构建,根据我们的规划,要将子项目全部构建出来,今天重点讲解的是ant-config配置文件项目的构建过程。 导语: 将ant-config项目独立出来的目的是将所有的配置文件进行统一项目管理,其中包括:spring相关文件配置、mybatis相关文件配置、数据源相关文件配置、基础环境文件配置(短信、消息、oss存储、第三方登陆、邮件等)、redis或者ehcache缓存相关配置、log4j日志文件相关配置、统一error异常配置、spring-shiro权限的相关配置、spring和redis缓存集成相关配置等。 1. 创建ant-config子项目,继承ant-parent项目,eclipse的创建过程我这边省略了。pom.xml文件配置如下: <span style="font-size: 16px;"><?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sml.sz</groupId>
<artifactId>ant-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>ant-config</artifactId>
<name>ant-config</name>
<url>http://maven.apache.org</url>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<!-- maven 打包后的包名 -->
<finalName>ant-config</finalName>
<resources>
<!-- 指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
<!-- 根据env部署环境值,把对应环境的配置文件拷贝到classes目录 -->
<resource>
<directory>deployEnv/${env}</directory>
<targetPath>${project.build.directory}/classes</targetPath>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
</span>
2. 创建log4j.properties文件,配置如下:
<span style="font-size: 16px;"># Output pattern : date [thread] priority category - message FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7
log4j.rootLogger=WARN, Console, RollingFile
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d %-5p [%c{5}] - %m%n
#RollingFile
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.File=/logs/ant/ant.log
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
#log4j.logger.java.sql=DEBUG
#Project defalult level
log4j.logger.com.sml.sz=DEBUG
log4j.logger.com.sml.sz.common.security.shiro=WARN
log4j.logger.com.sml.sz.JedisUtils=WARN</span>
3. 创建ant.properties文件,内容如下:
<span style="font-size: 16px;">#--------------Database sttings--------------
#mysql database setting
jdbc.type=mysql
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/ant-dubbo?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
#pool settings
jdbc.pool.init=10
jdbc.pool.minIdle=30
jdbc.pool.maxActive=60
#--------------redis settings--------------
redis.keyPrefix=ant
redis.host=127.0.0.1
redis.port=6379
#-------------- System settings --------------
#\u4ea7\u54c1\u4fe1\u606f\u8bbe\u7f6e
logoName=ant
productName=ant \u5206\u5E03\u5F0F\u4F01\u4E1A\u67B6\u6784
copyrightYear=2017
version=V1.0.0
#\u662f\u5426\u5141\u8bb8\u591a\u8d26\u53f7\u540c\u65f6\u767b\u5f55
user.multiAccountLogin=true
#\u5206\u9875\u914d\u7f6e
page.pageSize=10
#-------------- Framework settings --------------
#\u4f1a\u8bdd\u8d85\u65f6\uff0c \u5355\u4f4d\uff1a\u6beb\u79d2\uff0c 20m=1200000ms, 30m=1800000ms, 60m=3600000ms
session.sessionTimeout=1800000
#\u4f1a\u8bdd\u6e05\u7406\u95f4\u9694\u65f6\u95f4\uff0c \u5355\u4f4d\uff1a\u6beb\u79d2\uff0c2m=120000ms\u3002
session.sessionTimeoutClean=120000
#\u89c6\u56fe\u6587\u4ef6\u5b58\u653e\u8def\u5f84
web.view.prefix=/WEB-INF/views/
web.view.suffix=.jsp
web.maxUploadSize=10485760
#\u9759\u6001\u6587\u4ef6\u540e\u7f00
web.staticFile=.css,.js,.png,.jpg,.gif,.jpeg,.bmp,.ico,.swf,.psd,.htc,.htm,.html,.crx,.xpi,.exe,.ipa,.apk
#--------------Email SMTP --------------
mail.host=smtp.163.com
mail.port=25
mail.username=test@163.com
mail.password=test
mail.smtp.auth=true
mail.smtp.timeout=30000
mail.default.from=test@163.com
#-------------- JMS --------------
mq.brokerURL=failover\:(tcp\://127.0.0.1\:61616)?randomize\=false&initialReconnectDelay\=1000&maxReconnectDelay\=30000
mq.userName=ant
mq.password=ant
mq.pool.maxConnections=20
#queueName
queueName.task=task_queue_1
</span>
欢迎大家跟我一起学习《构建dubbo分布式平台》,希望大家持续关注后面的文章!
|