0

I don't understand very well because in my website application, js and css files are not found. In the source code, the url goes to localhost:8080/dashboard/css/bootstrap.min.css for example.

Here is the initializer :

@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));
}

And the config

@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;
}

}

And the 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>

Does anyone know how to do ?

3
  • problem solved i have added servletContext.getServletRegistration ("default").addMapping (".js", ".css", ".jpg", ".gif", "*.png"); in the initializer Commented Feb 26, 2013 at 9:23
  • You can add the default mapping in web.xml also Commented Feb 26, 2013 at 9:49
  • i'm not using a web.xml Commented Feb 26, 2013 at 12:30

1 Answer 1

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

Need to be added in your *-servlet.xml for loading all the static resources. Please refer Spring Documentation explaining same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.