带有嵌入式Jetty静态资源的Spring MVC

时间:2014-11-11 11:40:58

标签: java spring spring-mvc embedded-jetty static-resource

我正在使用Embedded Jetty:

 ServletContextHandler context = new ServletContextHandler();
 JettyHttpThreadPool jettyHttpThreadPool = new JettyHttpThreadPool(serviceName);
 server.setHandler(context);
 server.start();

我的春天上下文xml文件是:

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="mapper"/>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

<mvc:resources mapping="css/**" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="images/**" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="lib/**" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="swagger-ui.js" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/" location="classpath:/META-INF/resources/"/>

<bean id="mapper" class="com.rest.utils.ObjectMapperFactory"/>

<context:annotation-config/>
<context:component-scan base-package="com.rest"/>

当我尝试获取http://localhost:8080/index.html时,我会收到404 http状态代码。

我做错了什么?为什么我不能获得静态资源?

1 个答案:

答案 0 :(得分:0)

问题是另一个servlet的映射应该是“/”而不是“/ *”