Java 如何配置嵌入式Jetty以拾取web片段?
我的Java应用程序使用嵌入式Jetty 9.2.2。我在pom.xml中添加了一个库,其中包含web_fragment.xml文件。但是这个碎片没有被码头捡到。启动应用程序时,我可以在日志中看到库已加载。但是,当从库向servlet发出请求时,应用程序返回404。 如何让它发挥作用 该应用程序中有一个Spring配置文件dispatcher-servlet.xml,其中包含该库:Java 如何配置嵌入式Jetty以拾取web片段?,java,xml,spring,configuration,jetty,Java,Xml,Spring,Configuration,Jetty,我的Java应用程序使用嵌入式Jetty 9.2.2。我在pom.xml中添加了一个库,其中包含web_fragment.xml文件。但是这个碎片没有被码头捡到。启动应用程序时,我可以在日志中看到库已加载。但是,当从库向servlet发出请求时,应用程序返回404。 如何让它发挥作用 该应用程序中有一个Spring配置文件dispatcher-servlet.xml,其中包含该库: <import resource="classpath:/web.fragment.lib.spring.x
<import resource="classpath:/web.fragment.lib.spring.xml" />
没有web.xml文件,但应用程序包含带有映射的spring.xml文件。它使用dispatcher-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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-lazy-init="false">
<context:annotation-config/>
<context:property-placeholder system-properties-mode="FALLBACK" location="classpath:config.properties"/>
<bean name="WebServer" class="org.eclipse.jetty.server.Server" init-method="start">
<property name="connectors">
<list>
<bean name="LocalSocket" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg ref="WebServer"/>
<property name="host" value="0.0.0.0"/>
<property name="port" value="${jetty.port}"/>
</bean>
</list>
</property>
<property name="handler">
<bean class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="sessionHandler">
<bean class="org.eclipse.jetty.server.session.SessionHandler"/>
</property>
<property name="contextPath" value="${context.path}"/>
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="dispatcherServlet"/>
<property name="servlet">
<bean class="org.springframework.web.servlet.DispatcherServlet"/>
</property>
<property name="initParameters">
<map>
<entry key="contextConfigLocation" value="**classpath:dispatcher-servlet.xml**"/>
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="pathSpecs">
<list>
<value>/</value>
</list>
</property>
<property name="servletName" value="dispatcherServlet"/>
</bean>
</list>
</property>
</bean>
</property>
</bean>
</list>
</property>
</bean>
</property>
</bean>
</beans>
/
在您的示例中,两者都没有使用。
在嵌入式意义上,您正在使用Jetty,并且正在手动构建servlet列表
您必须切换到通过WebAppContext构建应用程序,或者手动添加这些web片段提供的功能
需要了解的重要一点是,web片段是webapp描述符的片段,这是webapp的一个复杂功能,由WebAppContext跟踪,由特定WebAppContext中定义的配置层列表配置。另请参阅: