0
我不太明白,因爲在我的網站應用程序中,找不到js和css文件。 在源代碼中,url例如轉到localhost:8080/dashboard/css/bootstrap.min.css。Spring 3.1找不到css&js
這裏是初始化:
@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>
有誰知道該怎麼辦?在* -servlet.xml後綴添加
問題解決 我已經添加 servletContext.getServletRegistration( 「默認」)。addMapping( 「* .js文件」, 「*。的CSS」, 「* .JPG」, 「* .gif注意」,「*。 PNG「); 在初始化程序中 – BkSouX 2013-02-26 09:23:53
您也可以在web.xml中添加默認映射 – Kris 2013-02-26 09:49:24
我沒有使用web.xml – BkSouX 2013-02-26 12:30:44