j今天部署了一个maven项目,具体的配置如下:
spring-jetty.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="Server" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop"> <property name="connectors"> <list> <bean class="org.eclipse.jetty.server.nio.SelectChannelConnector"> <property name="port" value="80" /> <!-- <property name="maxIdleTime" value="30000" /> <property name="requestHeaderSize" value="8192" />--> </bean> </list> </property> <property name="handler"> <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList"> <property name="handlers"> <list> <bean id="omcWeb" class="org.eclipse.jetty.webapp.WebAppContext"> <property name="contextPath" value="/" /> <property name="descriptor" value=".\src\webapp\WEB-INF\web.xml" /> <!-- <property name="war" value="." /> --> <property name="resourceBase" value=".\src\webapp" /> <property name="parentLoaderPriority" value="true" /> <property name="logUrlOnStart" value="true" /> </bean> <bean class="org.eclipse.jetty.server.handler.DefaultHandler"/> </list> </property> </bean> </property> </bean> </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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ExpressDoor2</display-name>
<welcome-file-list>
<welcome-file>html/index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/applicationContext.xml</param-value>
</context-param>
</web-app>
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:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation=" http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config/> <bean class = "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <import resource="hibernate.xml"/> </beans>
spring-servlet.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <mvc:resources location="/" mapping="/**/*.html"/> <mvc:resources location="/" mapping="/**/*.js"/> <mvc:resources location="/" mapping="/**/*.jsp"/> <mvc:resources location="/" mapping="/**/*.css"/> <mvc:resources location="/" mapping="/**/*.jpg"/> <mvc:resources location="/" mapping="/**/*.woff"/> <mvc:resources location="/" mapping="/**/*.ttf"/> <mvc:resources location="/" mapping="/**/*.png"/> <context:component-scan base-package="main.java"> </context:component-scan> <mvc:annotation-driven/> <mvc:default-servlet-handler/> <bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean> <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 --> <property name="maxUploadSize" value="2000000"/> </bean> <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException --> <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 --> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 --> <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop> </props> </property> </bean> </beans>
完成后启动项目,无论输入什么路径都不能访问到html,找了半天原来是spring-jetty.xml配置文件中配置server的handler属性中的handlers中有一个properties:resourceBase这个属性应该配置正确的放web.xml
的上一级的上一级目录,如
如果我的web文件配置为:.\src\webapp\WEB-INF\web.xml
那么我的resourceBase就应该为:.\src\webapp
相关推荐
详细介绍Eclipse+maven+jetty开发环境搭建
利用maven搭起的Spring MVC+Mybatis框架,并带有数据库表结构,使用者可直接导入mysql使用,有主外键关系
maven+jetty 的ssh框架例子 直接运行 run:jetty
java开发中Eclipse+maven+jetty环境配置
dwr+maven+jetty,具体参考:http://blog.csdn.net/xiejx618/article/details/20130139
struts2+maven+jetty 搭建java webapp。使用jetty:run命令运行。
idea+maven+jetty,整合最简单实例。
maven使用jetty启动,在pom.xml文件中添加Jetty plugin引用
一、安装Maven与设置环境 二、安装m2eclipse插件(不是必需的,这里我没安装) 三、修改仓库位置 四、创建maven项目 五、编译项目代码 六、导入eclipse工具 ...八、eclipse+struts2+maven2+jetty Maven中常用命令
简单的spring+jetty项目骨架,轻松构建web项目,适合练手
手把手教你搭建maven管理项目,用jetty服务器部署(有PDF详细图解),同时用 SpringMVC 实现了 excel+world导出和zip压缩包下载 技术包涵了:java,freemark,SpringMVC,相关Utils 亲手自作 excel+world导出+...
springmvc+maven+ibatis+jetty的pom配置文件,平时书写太麻烦
maven+ssm整合maven+ssm整合maven+ssm整合maven+ssm整合
NULL 博文链接:https://zxf-noimp.iteye.com/blog/806399
NULL 博文链接:https://wgbaoweii.iteye.com/blog/1856735
基于spring boot + maven + opencv 实现的图像深度学习Demo项目,包含车牌识别、人脸识别、证件识别等功能,贯穿样本处理、模型训练、图像处理、对象检测、对象识别等技术点。 基于spring boot + maven + opencv ...
基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+maven+httpClient+jsoup实现小说网站项目 基于SSM+...