0

我不是很明白,因为在我的网站应用程序中,没有找到js和css文件。例如,在源代码中,url 转到 localhost:8080/dashboard/css/bootstrap.min.css。

这是初始化程序:

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    appContext.getEnvironment().setActiveProfiles("resthub-mongodb", "resthub-web-server");
    String[] locations = { "classpath*:resthubContext.xml", "classpath*:applicationContext.xml" };
    appContext.setConfigLocations(locations);
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(appContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");  
    servletContext.addListener(new ContextLoaderListener(appContext));
}

和配置

@Configuration
@ComponentScan("org.resthub.dashboard")
@EnableWebMvc
public class WebAppConfig {

@Bean
public InternalResourceViewResolver setupViewResolver() {
   InternalResourceViewResolver resolver = new InternalResourceViewResolver();
   resolver.setPrefix("/WEB-INF/views/");
   resolver.setSuffix(".jsp");
   return resolver;
}

}

和 applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/mvc 
                            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
                           http://www.springframework.org/schema/data/mongo 
                           http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">

    <context:component-scan base-package="org.resthub.dashboard" />
    <mongo:repositories base-package="org.resthub.dashboard.repository" />

    <mvc:annotation-driven />

</beans>

有谁知道该怎么做?

4

1 回答 1

2
<mvc:resources mapping="/resources/**" location="/resources/" />

需要在您的 *-servlet.xml 中添加以加载所有静态资源。请参阅Spring Documentation解释相同。

于 2013-02-26T11:40:19.497 回答