Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use spring MVC's <mvc:resources> tag in a java application context?
    primarykey
    data
    text
    <p>I have created 'for now' a simple and basic spring web application. I am used to have a deployment descriptor as a simple web.xml file, and then an application context as a xml file.</p> <p>Though, now i wanted to try to create my entire spring web application using only java files. Therefore i have created my WebApplicationInitializer instead of the normal deployment descriptor, and my application context which uses the @Configuration annotation.</p> <p><strong>Deployment Descriptor</strong> </p> <pre><code>package dk.chakula.config; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration.Dynamic; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; /** * * @author martin * @since 12-1-2012 * @version 1.0 */ public class Initializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { registerDispatcherServlet(servletContext); } private void registerDispatcherServlet(final ServletContext servletContext) { WebApplicationContext dispatcherContext = createContext(ChakulaWebConfigurationContext.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext); Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } private WebApplicationContext createContext(final Class&lt;?&gt;... annotatedClasses) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(annotatedClasses); return context; } } //End of class Initializer </code></pre> <p><strong>Application context</strong> </p> <pre><code>package dk.chakula.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.view.UrlBasedViewResolver; import org.springframework.web.servlet.view.tiles2.TilesConfigurer; import org.springframework.web.servlet.view.tiles2.TilesView; /** * * @author martin * @since 12-01-2013 * @version 1.0 */ @Configuration @EnableWebMvc @ComponentScan("dk.chakula.web") public class ChakulaWebConfigurationContext { @Bean public TilesConfigurer setupTilesConfigurer() { TilesConfigurer configurer = new TilesConfigurer(); String[] definitions = {"/layout/layout.xml"}; configurer.setDefinitions(definitions); return configurer; } @Bean public UrlBasedViewResolver setupTilesViewResolver() { UrlBasedViewResolver viewResolver = new UrlBasedViewResolver(); viewResolver.setViewClass(TilesView.class); return viewResolver; } } //End of class ChakulaWebConfigurationContext </code></pre> <p>My problem is that I can't seem to find a way 'isolate' my mapping to resources folder which contains images, css javascript etc. When my application context is in java.</p> <p>With the normal XML application context I used this tag to isolate the mapping to /resources/</p> <pre><code>&lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt; </code></pre> <p>How can I do this, so my web application can use my images, css etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload