大神的YMP框架:https://github.com/suninformation/ymateplatform.git
1. 新建Maven project
打开新建项目对话框,选择Maven Project(File->New->Object->Maven->Maven Project)
直接next即可
选择名为webapp的Archetype,点击Next
Archetype:项目骨架,项目的目录和文件结构
输入Group Id,Artifact Id信息,Version默认为0.0.1-SNAPSHOT,Package会根据Group Id和Artifact Id自动生成 (设为空即可)
Group Id:项目所属的项目组
Artifact Id:项目在项目组中的ID
Version:项目的版本号,后缀SNASHOT为快照的意思,表示版本不稳定
点击Finish 完成
2. 配置文件
(1) pom.xml
添加YMP框架jar包
修改pom.xml 添加YMP框架jar包,保存,jar包即可自动导入到工程。
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ympWeb-group</groupId>
<artifactId>ympWeb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ympWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.ymate.platform</groupId>
<artifactId>ymate-platform</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>ympWeb</finalName>
</build>
</project>
(2) web.xml
修改web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>net.ymate.platform.mvc.web.WebMvcEventListener</listener-class>
</listener>
<filter>
<filter-name>ymatemvc</filter-name>
<filter-class>net.ymate.platform.mvc.web.DispatcherFilter</filter-class>
<init-param>
<param-name>ignore</param-name>
<param-value>^.+\.(png|jsp|gif|jpg|js|css|jspx|jpeg|swf|ico|htm|woff|ttf|svg)$</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ymatemvc</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
(3) ymp-conf.properties
YMP框架主要的配置文件
ymp-conf.properties详细配置内容参考: https://github.com/suninformation/ymateplatform/wiki/YMP框架初始化配置文件详细说明
建立ymp-conf.properties 文件:/src/main/resources/ymp-conf.properties
# 是否为开发模式,默认为false
ymp.dev_model=false
# 模块列表,多个模块用"|"分隔,注意加载顺序
ymp.module_list=configuration|logger|webmvc
# 模块自定义配置,以ymp.configs字符串+模块名称开始,后跟模块配置项,以英文句点分隔
ymp.configs.configuration.config_home=${root}
ymp.configs.logger.name=default
ymp.configs.logger.level=all
ymp.configs.logger.xml_cfg_file=${user.dir}cfgs/log4j.xml
ymp.configs.logger.output_path=${user.dir}logs/
ymp.configs.logger.allow_print_console=true
(4) log4j.xml
建立log4j.xml文件:WEB-INF/cfgs/log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "/org/apache/log4j/xmllog4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Root日志记录器配置,适配框架及其它开源项目的日志内容输出 -->
<appender name="RootFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${LOGS_DIR}/logger-root.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyMMddHH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss,SSS}] [%p] [%l] %x - %m%n" />
</layout>
</appender>
<!-- 具体业务日志记录器配置 -->
<appender name="FileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${LOGS_DIR}/logger-default.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyMMddHH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<appender name="TestFileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${LOGS_DIR}/logger-test.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyMMddHH" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
<!-- 日志记录器定义,可定义多个记录器 -->
<logger name="default">
<level value="debug" />
<appender-ref ref="FileAppender" />
</logger>
<logger name="test">
<level value="debug" />
<appender-ref ref="TestFileAppender" />
</logger>
<!-- 根logger的设置-->
<root>
<priority value ="debug"/>
<appender-ref ref="RootFileAppender"/>
</root>
</log4j:configuration>
(5) 部署到Tomcat容器并启动,检查日志输出,确认框架配置是否成功
来源:oschina
链接:https://my.oschina.net/u/1864314/blog/285899