Как использовать тег <mvc: resources> Spring MVC в контексте приложения Java?

Я создал 'теперь' простое и простое весеннее веб-приложение. Я привык иметь дескриптор развертывания в виде простого файла web.xml, а затем контекст приложения в виде файла xml.

Хотя, теперь я хотел попробовать создать все мое весеннее веб-приложение, используя только файлы Java. Поэтому я создал свой WebApplicationInitializer вместо обычного дескриптора развертывания и контекст моего приложения, который использует аннотацию @Configuration.

Дескриптор развертывания

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... annotatedClasses) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(annotatedClasses);
        return context;
    }

} //End of class Initializer

Контекст приложения

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

Моя проблема в том, что я могукажется, не найти способизолировать» мое сопоставление с папкой ресурсов, которая содержит изображения, CSS JavaScript и т. д., когда мой контекст приложения находится в Java.

В обычном контексте приложения XML я использовал этот тег, чтобы изолировать отображение на / resources /


Как я могу это сделать, чтобы мое веб-приложение могло использовать мои изображения, CSS и т. Д.

Ответы на вопрос(3)

Ваш ответ на вопрос