j deployed a maven project today , the specific configuration is as follows:
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> <!-- When SpringMVC uploads files, you need to configure the MultipartResolver processor--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> <!-- Specifies that the total size of the uploaded files cannot exceed 200KB. Note that the limit of the maxUploadSize property is not for a single file, but the sum of the capacities of all files --> <property name="maxUploadSize" value="2000000"/> </bean> <!-- SpringMVC will throw org.springframework.web.multipart.MaxUploadSizeExceededException when it exceeds the upload file limit --> <!-- This exception is thrown by SpringMVC when checking the uploaded file information, and it has not entered the Controller method at this time --> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <!-- When MaxUploadSizeExceededException is encountered, automatically jump to /WEB-INF/jsp/error_fileupload.jsp page--> <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop> </props> </property> </bean> </beans>
After starting the project, no matter what path is entered, html cannot be accessed. After searching for a long time, it turns out that there is a properties in the handlers in the handler property of the server configured in the spring-jetty.xml configuration file: resourceBase This property should be configured correctly and put on the web .xml
The parent directory of the previous level, such as
If my web file is configured as: .\src\webapp\WEB-INF\web.xml
Then my resourceBase should be: .\src\webapp