Spring MVC 搭建配置
mvc-servlet.xml
集成Jsp、Freemarker、Velocity视图解析
<?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" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" default-lazy-init="false"> <!-- 自动扫描且只扫描@Controller --> <context:component-scan base-package="com.yofoto" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> </context:component-scan> <aop:aspectj-autoproxy proxy-target-class="true" /> <!-- 开启Spring mvc 注解支持 --> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"> <mvc:message-converters register-defaults="true"> <!-- 从HTTP请求和响应读取/编写字符串,支持媒体类型 text/* 并使用文本/无格式内容类型编写 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8" index="0" /> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>application/xml;charset=UTF-8</value> </list> </property> </bean> <!-- 从Http请求和响应读取/编写表单数据,支持媒体类型 application/x-www-form-urlencoded 并将数据写入 MultiValueMap<String,String> --> <bean class="org.springframework.http.converter.FormHttpMessageConverter"/> <!-- 从HTTP请求和响应写入的字节数组 --> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <!-- fastjson转换器 --> <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>text/json;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <property name="features"> <array> <!-- QuoteFieldNames 输出key时是否使用双引号,默认为true WriteMapNullValue 是否输出值为null的字段,默认为false WriteNullNumberAsZero 数值字段如果为null,输出为0,而非null WriteNullListAsEmpty List字段如果为null,输出为[],而非null WriteNullStringAsEmpty 字符类型字段如果为null,输出为"",而非null WriteNullBooleanAsFalse Boolean字段如果为null,输出为false,而非null --> <!--NULL过滤--> <value>QuoteFieldNames</value> <value>WriteMapNullValue</value> <value>WriteNullStringAsEmpty</value> <value>WriteNullListAsEmpty</value> <value>WriteNullNumberAsZero</value> <value>WriteNullBooleanAsFalse</value> <!--斜杠处理--> <value>WriteSlashAsSpecial</value> </array> </property> </bean> <!-- 使用 Spring 的 marshaller/un-marshaller 读取/编写 XML 数据,转换媒体类型为 application/xml 的数据 --> <bean id="xmlHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"> <constructor-arg ref="jaxb2Marshaller" /> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>text/xml;charset=UTF-8</value> <value>application/xml;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- JAXB to XML --> <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <!-- 按命名包扫描 --> <property name="packagesToScan"> <list> <value>com.yofoto.model</value> </list> </property> <!-- 按命名类扫描 <property name="classesToBeBound"> <list> <value>com.yofoto.model.Person</value> </list> </property> --> </bean> <!--1、检查扩展名;2、检查Parameter;3、检查Accept Header--> <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <!-- 设置为true以忽略对Accept Header的支持--> <property name="ignoreAcceptHeader" value="true"/> <!-- 用于关闭 /userinfo/123.json 的支持 默认是true --> <property name="favorPathExtension" value="true" /> <!-- 用于开启 /userinfo/123?format=json 的支持 --> <property name="favorParameter" value="true" /> <property name="parameterName" value="mediaType" /> <!-- 在没有扩展名时即: "/user/1" 时的默认展现形式 --> <property name="defaultContentType" value="text/html" /> <!-- 扩展名至mimeType的映射,即 /user.json => application/json --> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </map> </property> </bean> <!-- 内容策略视图解析器;根据客户端不同的请求决定不同的view进行响应 --> <!-- 会自动根据解析的contentType来决定使用哪个视图解析器(默认使用整个web应用中的viewResolver) --> <bean id="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <!--加载视图解析器顺序 --> <property name="order" value="0" /> <!-- 内容协商管理器 用于决定media type --> <property name="contentNegotiationManager" ref="contentNegotiationManager" /> <!-- 配置视图解析器--> <property name="viewResolvers"> <list> <!-- velocity视图解析器 --> <bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <!-- 配置 velocity视图,需引入velocity.jar --> <property name="viewClass" value="com.yofoto.view.VelocityToolbox2View"/> <property name="contentType" value="text/html; charset=UTF-8"/> <property name="cache" value="true"/><!--是否缓存模板--> <property name="prefix" value=""/> <property name="suffix" value=".vm"/> <property name="exposeRequestAttributes" value="true" /><!--是否开放request属性--> <property name="requestContextAttribute" value="request" /><!--request属性引用名称--> <property name="exposeSessionAttributes" value="true" /><!--是否开放session属性--> <property name="exposeSpringMacroHelpers" value="true" /><!--是否使用spring对宏定义的支持--> <property name="toolboxConfigLocation" value="/WEB-INF/classes/velocity/toolbox.xml" /><!--toolbox配置文件路径--> <property name="order" value="3" /> </bean> <!-- freemarker视图解析器 --> <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <!-- 配置 freemarker视图,需引入freemarker.jar--> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> <property name="contentType" value="text/html; charset=UTF-8" /> <property name="cache" value="true"/><!--是否缓存模板--> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> <property name="exposeRequestAttributes" value="true" /><!--是否开放request属性--> <property name="requestContextAttribute" value="request" /><!--request属性引用名称--> <property name="exposeSessionAttributes" value="true" /><!--是否开放session属性--> <property name="exposeSpringMacroHelpers" value="true" /><!--是否使用spring对宏定义的支持--> <property name="order" value="4" /> </bean> <!-- jsp视图解析器 --> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置 jstl 视图,需引入jstl.jar--> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="contentType" value="text/html; charset=UTF-8"/> <property name="prefix" value="" /> <property name="suffix" value=".jsp" /> <property name="order" value="5" /> </bean> </list> </property> <!-- 默认视图 放在解析链最后 --> <property name="defaultViews"> <list> <!-- 指定了HttpMessageConverter转换器,不需要指定view <bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView" /> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <constructor-arg ref="jaxb2Marshaller" /> </bean> --> </list> </property> </bean> <!-- 视图解析器,根据视图的名称new ModelAndView(name),在配置文件查找对应的bean配置 --> <bean id="beanViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"> <property name="order" value="1"/> </bean> <!-- velocity环境配置 --> <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="configLocation" value="classpath:velocity/velocity.properties"/><!-- 加载velocity属性配置 --> <property name="resourceLoaderPath" value="/WEB-INF/vm"/><!-- 页面文件的路径,相对于webapp --> <property name="velocityProperties"> <props> <prop key="input.encoding">UTF-8</prop><!-- 指定模板引擎进行模板处理的编码 --> <prop key="output.encoding">UTF-8</prop><!-- 指定输出流的编码 --> </props> </property> </bean> <!-- freeMarker环境配置 --> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/ftl"/><!-- 页面文件的路径,相对于webapp --> <property name="defaultEncoding" value="UTF-8" /><!-- 默认编码 --> <property name="freemarkerVariables"><!-- 变量引用 --> <map> <entry key="xml_escape" value-ref="fmXmlEscape"/> </map> </property> <property name="freemarkerSettings" ref="freemarkerSetting" /><!-- 属性设置 --> </bean> <bean id="freemarkerSetting" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:freemarker/freemarker.properties"/><!-- 加载freemarker属性配置 --> </bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/> <!-- 过滤静态资源拦截,并缓存一年 --> <mvc:resources mapping="/css/**" location="/static/css/" cache-period="31536000"/> <mvc:resources mapping="/js/**" location="/static/js/" cache-period="31536000"/> <mvc:resources mapping="/images/**" location="/static/images/" cache-period="31536000"/> <mvc:view-controller path="/" view-name="redirect:/index"/> <!-- 定义异常处理页面 --> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">error/500</prop> </props> </property> <!-- 定义在发生异常时视图跟返回码的对应关系 --> <property name="statusCodes"> <props> <prop key="error/500">500</prop> <prop key="error/404">404</prop> </props> </property> <!--定义异常处理页面用来获取异常信息的变量名,默认名value为exception--> <property name="exceptionAttribute" value="ex" /> <!-- 设置日志输出级别,不定义则默认不输出警告等错误日志信息 --> <property name="warnLogCategory" value="WARN" /> <!-- 表示当抛出异常但没有在exceptionMappings里面找到对应的异常时 返回名叫exception的视图--> <property name="defaultErrorView" value="error/exception" /> <!-- 表示在发生异常时默认的HttpServletResponse的返回码是多少,默认是200 --> <property name="defaultStatusCode" value="500" /> </bean> </beans>
applicationContext.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" xmlns:aop="http://www.springframework.org/schema/aop" 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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" default-lazy-init="false"> <!-- 自动扫描包注释 --> <context:component-scan base-package="com.yofoto" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/> <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan> <aop:aspectj-autoproxy /> </beans>
web.xml
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>web-site</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>webapp.root</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <servlet> <servlet-name>springMvcServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvcServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>httpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>httpMethodFilter</filter-name> <servlet-name>springMvcServlet</servlet-name> </filter-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error/500.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/500.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/error/404.jsp</location> </error-page> </web-app>
freemarker.properties
tag_syntax=auto_detect template_update_delay=5 default_encoding=UTF-8 output_encoding=UTF-8 url_escaping_charset=UTF-8 locale=zh_CN time_format=HH:mm:ss date_format=yyyy-MM-dd datetime_format=yyyy-MM-dd HH:mm:ss number_format=0.###### whitespace_stripping=true boolean_format=true,false
velocity.properties
input.encoding=UTF-8 output.encoding=UTF-8 velocimacro.library.autoreload=true file.resource.loader.cache=false directive.foreach.counter.name=velocityCount directive.foreach.counter.initial.value=1 #------- 注释文件待研究 #类路径加载模板文件 #resource.loader=class #class.resource.loader.description=Velocity Classpath Resource Loader #class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClassPathResourceLoader #默认文件路径加载模板文件 #resource.loader=file #file.resource.loader.description=Velocity File Resource Loader #file.resource.loader.class=org.apache.velocity.runtime.resource.loader.FileResourceLoader #file.resource.loader.path=. #file.resource.loader.path=${webapp.root}/WEB-INF/vm #file.resource.loader.cache=false #file.resource.loader.modificationCheckInterval=2
toolbox.xml
<?xml version="1.0" encoding="UTF-8"?>
<toolbox>
<tool>
<key>date</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<tool>
<key>escape</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
<tool>
<key>number</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
</tool>
<tool>
<key>math</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
<tool>
<key>cookie</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.CookieTool</class>
</tool>
<!-- 获取当前应用的contextPath,${link.contextPath} -->
<tool>
<key>link</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.LinkTool</class>
</tool>
<!-- 获取url参数, $params.returnUrl,来获取类似 http://xxx.com/login?returnUrl=abc 中的 abc部分 -->
<tool>
<key>params</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.ParameterTool</class>
</tool>
</toolbox>
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>com.yofoto</groupId> <artifactId>web-site</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>web-site Maven Webapp</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>io.spring.repo.maven.release</id> <url>http://repo.spring.io/release/</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format> <jdk.version>1.6</jdk.version> <spring.version>3.2.5.RELEASE</spring.version> <aopalliance.version>1.0</aopalliance.version> <aspectj.version>1.6.9</aspectj.version> <velocity.version>1.7</velocity.version> <velocity-tools.version>2.0</velocity-tools.version> <freemarker.version>2.3.20</freemarker.version> <!-- Log Version --> <slf4j.version>1.7.6</slf4j.version> <logback.version>1.1.2</logback.version> <!-- Util Version --> <commons-logging.version>1.1.1</commons-logging.version> <commons-lang.version>2.6</commons-lang.version> <commons-collections.version>3.2.1</commons-collections.version> <commons-beanutils.version>1.8.3</commons-beanutils.version> <commons-io.version>2.4</commons-io.version> <commons-codec.version>1.8</commons-codec.version> <commons-fileupload.version>1.3</commons-fileupload.version> <junit.version>4.12</junit.version> <!-- Maven Plugin Version --> <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven-resources-plugin.version>2.3</maven-resources-plugin.version> <maven-source-plugin.version>2.3</maven-source-plugin.version> <maven-jar-plugin.version>2.4</maven-jar-plugin.version> <maven-war-plugin.version>2.4</maven-war-plugin.version> <maven-dependency-plugin.version>2.8</maven-dependency-plugin.version> <maven-surefire-plugin.version>2.17</maven-surefire-plugin.version> <jetty.version>8.1.16.v20140903</jetty.version> </properties> <dependencies> <!-- Springframework begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!-- Springframework end --> <!-- Aop begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>${aopalliance.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> <!-- Aop end --> <!-- Web begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <!-- Web end --> <!-- Page Template begin --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>${velocity.version}</version> <exclusions> <exclusion> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </exclusion> <exclusion> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-tools</artifactId> <version>${velocity-tools.version}</version> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>${freemarker.version}</version> </dependency> <!-- Page Template end --> <!-- JSON begin --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${alibaba-fastjson.version}</version> </dependency> <!-- JSON end --> <!-- LOG begin --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>${commons-logging.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> <version>${slf4j.version}</version> </dependency> <!--<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency>--> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>${logback.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-access</artifactId> <version>${logback.version}</version> <scope>runtime</scope> </dependency> <!-- LOG end --> <!-- Utils begin --> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>${commons-lang.version}</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>${commons-collections.version}</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>${commons-beanutils.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <!-- Utils end --> <!-- Test begin--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <!-- Test end--> </dependencies> <build> <finalName>web-site</finalName> <!-- =================== --> <!-- Java compile plugin --> <!-- =================== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <compilerVersion>${jdk.version}</compilerVersion> <source>${jdk.version}</source> <target>${jdk.version}</target> <encoding>${project.build.sourceEncoding}</encoding> <showWarnings>true</showWarnings> </configuration> </plugin> <!-- ================== --> <!-- Java resources plugin --> <!-- ================== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>${maven-resources-plugin.version}</version> <executions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>${project.build.sourceEncoding}</encoding> <outputDirectory>${project.build.outputDirectory}</outputDirectory> <resources> <resource> <directory>src/main/resources/</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> <configuration> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> <!-- ============== --> <!-- Java source plugin --> <!-- ================== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>${maven-source-plugin.version}</version> <executions> <execution> <id>attach-sources</id> <phase>verify</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- ============== --> <!-- dependency plugin --> <!-- ============== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>${maven-dependency-plugin.version}</version> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <includeScope>compile</includeScope> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- ============== --> <!-- jar plugin --> <!-- ============== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>${maven-jar-plugin.version}</version> <configuration> <archive> <index>true</index> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> </manifest> <manifestEntries> <Build-Version>${project.version}-${maven.build.timestamp}</Build-Version> </manifestEntries> </archive> </configuration> </plugin> <!-- ============== --> <!-- war plugin --> <!-- ============== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>${maven-war-plugin.version}</version> <configuration> <warName>${project.artifactId}</warName> <archive> <index>true</index> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> </manifest> <manifestEntries> <Build-Version>${project.version}-${maven.build.timestamp}</Build-Version> </manifestEntries> </archive> </configuration> </plugin> <!-- ============== --> <!-- automatic test--> <!-- ============== --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-junit47</artifactId> <version>${maven-surefire-plugin.version}</version> </dependency> </dependencies> <configuration> <skip>false</skip><!-- is True,skip test --> <includes> <include>**/*Test.java</include> </includes> <argLine>-Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8</argLine> <forkMode>once</forkMode> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> <!-- 配置jetty启动 --> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty.version}</version> <configuration> <stopKey>foo</stopKey> <stopPort>9999</stopPort> <encoding>UTF-8</encoding> <connectors> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>80</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> <webApp> <contextPath>/</contextPath> </webApp> <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory> <contextXml>${basedir}/jetty-context.xml</contextXml> <scanIntervalSeconds>1</scanIntervalSeconds> <!-- 指定额外需要监控变化的文件或文件夹,主要用于热部署中的识别文件更新 <scanTargetPatterns> <scanTargetPattern> <directory>src</directory> <includes> <include>**/*.java</include> <include>**/*.properties</include> </includes> </scanTargetPattern> </scanTargetPatterns> --> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog"> <filename>target/access.log</filename> <retainDays>90</retainDays> <append>false</append> <extended>false</extended> <logTimeZone>GMT+8:00</logTimeZone> </requestLog> </configuration> </plugin> </plugins> </build> </project>
浙公网安备 33010602011771号