1.信贷路由项目架构
2.工程搭建及测试
搭建tyrRouter-parent,tyrRouter-log-web,工程采用 maven 构建
配置 pom.xml 文件,父项目管理 jar 包的版本号, 配置子项目jetty插件(rose 框架和 tomcat 插件不兼容),配置 web.xml, 新建页面 index.html 测试
3.rose 框架的搭建及测试
以tyrRouter-log-web为例搭建rose框架
配置 pom.xml 文件(rose,日志,mysql数据库,单元测试,lombok,filter动态配置)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.tcredit</groupId> <artifactId>tyrRouter</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>tyrRouter-log-web</artifactId> <packaging>war</packaging> <!-- 添加依赖:rose,日志,mysql数据库,单元测试,lombok --> <dependencies> <!-- rose --> <dependency> <groupId>net.paoding</groupId> <artifactId>rose</artifactId> </dependency> <dependency> <groupId>net.paoding</groupId> <artifactId>rose-pipe</artifactId> </dependency> <!-- 日志 --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- mysql数据库 --> <dependency> <groupId>com.wzzx</groupId> <artifactId>wzzx-datasource4jade</artifactId> </dependency> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> <!-- filter 配置 --> <profiles> <!-- 开发,默认激活 --> <profile> <id>dev</id> <properties> <env>dev</env> <env-s>-dev</env-s> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>mock</id> <properties> <env>mock</env> <env-s>-mock</env-s> </properties> </profile> <profile> <id>test</id> <properties> <env>test</env> <env-s>-test</env-s> </properties> </profile> <profile> <id>uat</id> <properties> <env>uat</env> <env-s>-uat</env-s> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> <env-s></env-s> </properties> </profile> </profiles> <build> <!-- filter 配置 --> <finalName>${project.artifactId}-${project.version}</finalName> <defaultGoal>compile</defaultGoal> <filters> <filter>${project.basedir}/filters/${env}/config.properties</filter> </filters> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <!--需要过滤的文件--> <include>*.*</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <excludes> <exclude>*.*</exclude> </excludes> </resource> </resources> <plugins> <!-- 构建 tomcat7插件,配置端口号8084, 运行方式: 选中项目右键-run as...-maven build.-goals输入:clean tomcat7:run- apply-run tomcat插件有问题 --> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.4.v20170414</version> <configuration> <scanIntervalSeconds>5</scanIntervalSeconds> <webApp> <contextPath>/</contextPath> </webApp> <connectors> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>8080</port> </connector> </connectors> </configuration> </plugin> <!-- <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
配置 filter.dev.config.properties 动态配置(也是项目环境变量,区别开发,测试,生产)
#mysql服务
tyr_host=localhost
tyr_r1_host=localhost
tyr_r2_host=localhost
database=tyr_dev_test
#日志
logPath=/Users/mryuan/work/log/stdout.log
#加密规则
yzj.appId=20e0c48206fd451b96ccb68702264250123
yzj.tokenId=78902351780041f0b325cecf34aec167102
配置 web.xml 文件(中文字符编码, rose 过滤器(内含自动扫描 applicationContext 文件))
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>tyrRouter-log-web</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- 中文字符编码, rose 过滤器 --> <!-- 中文字符编码 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- rose 过滤器 --> <filter> <filter-name>roseFilter</filter-name> <filter-class>net.paoding.rose.RoseFilter</filter-class> </filter> <filter-mapping> <filter-name>roseFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> </web-app>
配置 applicationContext-log-web.xml(自动扫描包,前端页面国际化)
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 扫描包 --> <context:component-scan base-package="com.tcredit.log" /> </beans>
配置 datasource.yaml 文件(数据库相关配置)
#公司环境数据库配置
auth:
admin : admin
#######################################
#mysql的默认连接配置
default:
type: mysql
port: 3306
initialSize: 1
maxActive: 20
maxWait: 10000
filters:
- stat
auth: root
#######################################
server:
#mysql服务
tyr:
host: ${tyr_host}
tyr_r1:
host: ${tyr_r1_host}
tyr_r2:
host: ${tyr_r2_host}
datasource:
tyr:
server: tyr
database: ${database}
auth: tyr
#auth: root
配置 log4j.properties 文件(日志相关配置)
log4j.rootCategory=info,stdout,MAIL
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %p [%t] %C.%M(%L) | %m%n
log4j.appender.stdout=org.apache.log4j.DailyRollingFileAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%t] %C.%M(%L) | %m%n
log4j.appender.stdout.encoding=UTF-8
log4j.appender.stdout.File=${logPath}
log4j.appender.stdout.DatePattern='.'yyyy-MM-dd
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
######################send error through email.######################
#log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
#log4j.appender.MAIL.Threshold=ERROR
#log4j.appender.MAIL.SMTPHost=smtp.mxhichina.com
#log4j.appender.mail.SMTPPort=465
#log4j.appender.MAIL.Subject=Systerm Error - tyr-mobile-web
#log4j.appender.MAIL.SMTPUsername=itsupport@tcredit.com
#log4j.appender.MAIL.SMTPPassword=Tcredit.com@2017
#log4j.appender.MAIL.From=itsupport@tcredit.com
#log4j.appender.MAIL.To=creditRouterDev@tcredit.com
#log4j.appender.MAIL.layout=com.tcredit.tyr.core.log4j.TyrHTMLLayout
配置 setting.properties 文件(配置项目所用到的环境变量)
#数据库配置
jade.datasource=datasource.yaml
#信用百科授权配置
yzj.appId=${yzj.appId}
yzj.tokenId=${yzj.tokenId}
新建包 controller,service,service.impl,dao,entity新建测试类,启动项目测试