私は、今のところ単純で基本的な春のWebアプリケーションを作成しました。私はデプロイメント記述子を単純なweb.xmlファイルとして、次にアプリケーションコンテキストをxmlファイルとして使用しています。Javaアプリケーションコンテキストでspring MVCの<mvc:resources>タグを使用するにはどうすればいいですか?
今、私はJavaファイルのみを使用して私の春のWebアプリケーション全体を作成しようとしたかったのですが。したがって、通常のデプロイメント記述子の代わりに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
私の問題は、私は方法を見つけるように見えることができないということですresourcesフォルダに自分のマッピングを '隔離' されイメージ、CSSのJavaScriptなどが含まれています。私のアプリケーションコンテキストがjavaにあるとき。私は/リソース/
<mvc:resources mapping="/resources/**" location="/resources/" />
私のWebアプリケーションは、私のイメージを使用することができますので、私は、これをどのように行うことができますへのマッピングを隔離するために、このタグを使用し、通常のXMLアプリケーションのコンテキストで
、CSSなど
あなたはどのバージョンを使用していますか? –
私は3.2.0を使用しています – Rohwedder