当前位置:   article > 正文

maven + jetty项目不能访问到正确路径的html页面

jetty jar 找不到html页面

j今天部署了一个maven项目具体的配置如下:

spring-jetty.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  5. <bean id="Server" class="org.eclipse.jetty.server.Server"
  6. init-method="start" destroy-method="stop">
  7. <property name="connectors">
  8. <list>
  9. <bean class="org.eclipse.jetty.server.nio.SelectChannelConnector">
  10. <property name="port" value="80" />
  11. <!-- <property name="maxIdleTime" value="30000" />
  12. <property name="requestHeaderSize" value="8192" />-->
  13. </bean>
  14. </list>
  15. </property>
  16. <property name="handler">
  17. <bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
  18. <property name="handlers">
  19. <list>
  20. <bean id="omcWeb" class="org.eclipse.jetty.webapp.WebAppContext">
  21. <property name="contextPath" value="/" />
  22. <property name="descriptor" value=".\src\webapp\WEB-INF\web.xml" />
  23. <!-- <property name="war" value="." /> -->
  24. <property name="resourceBase" value=".\src\webapp" />
  25. <property name="parentLoaderPriority" value="true" />
  26. <property name="logUrlOnStart" value="true" />
  27. </bean>
  28. <bean class="org.eclipse.jetty.server.handler.DefaultHandler"/>
  29. </list>
  30. </property>
  31. </bean>
  32. </property>
  33. </bean>
  34. </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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  10. http://www.springframework.org/schema/mvc
  11. http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd ">
  12. <mvc:resources location="/" mapping="/**/*.html"/>
  13. <mvc:resources location="/" mapping="/**/*.js"/>
  14. <mvc:resources location="/" mapping="/**/*.jsp"/>
  15. <mvc:resources location="/" mapping="/**/*.css"/>
  16. <mvc:resources location="/" mapping="/**/*.jpg"/>
  17. <mvc:resources location="/" mapping="/**/*.woff"/>
  18. <mvc:resources location="/" mapping="/**/*.ttf"/>
  19. <mvc:resources location="/" mapping="/**/*.png"/>
  20. <context:component-scan
  21. base-package="main.java">
  22. </context:component-scan>
  23. <mvc:annotation-driven/>
  24. <mvc:default-servlet-handler/>
  25. <bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
  26. <property name="messageConverters">
  27. <list>
  28. <bean
  29. class="org.springframework.http.converter.StringHttpMessageConverter">
  30. <property name="supportedMediaTypes">
  31. <list>
  32. <value>text/plain;charset=UTF-8</value>
  33. <value>text/html;charset=UTF-8</value>
  34. </list>
  35. </property>
  36. </bean>
  37. <bean id="mappingJacksonHttpMessageConverter"
  38. class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
  39. <property name="supportedMediaTypes">
  40. <list>
  41. <value>application/json;charset=UTF-8</value>
  42. <value>text/html;charset=UTF-8</value>
  43. </list>
  44. </property>
  45. </bean>
  46. </list>
  47. </property>
  48. </bean>
  49. <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
  50. <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  51. <property name="defaultEncoding" value="UTF-8"/>
  52. <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
  53. <property name="maxUploadSize" value="2000000"/>
  54. </bean>
  55. <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
  56. <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
  57. <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
  58. <property name="exceptionMappings">
  59. <props>
  60. <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->
  61. <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
  62. </props>
  63. </property>
  64. </bean>
  65. </beans>

 完成后启动项目,无论输入什么路径都不能访问到html,找了半天原来是spring-jetty.xml配置文件中配置server的handler属性中的handlers中有一个properties:resourceBase这个属性应该配置正确的放web.xml

的上一级的上一级目录,如

如果我的web文件配置为:.\src\webapp\WEB-INF\web.xml

那么我的resourceBase就应该为:.\src\webapp

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/271506
推荐阅读
相关标签
  

闽ICP备14008679号