私の究極の目標は、複数のサーブレット(MVC用とWebServices用)を同時に実行できるようにすることです。残念ながら、サーブレットマッピングがroot( "/")以外の場合、サーブレットをコントローラにルーティングすることはできません。Spring JavaConfigディスパッチャーサーブレットをroot以外のものにマップする方法
次のURLがコントローラを起動するとは思っていましたが、そうではありません。
http://localhost:8080/Sandbox/Page/Test
私は正常に動作-it URLからのservlet-mappingから '/ページ'、および '/ページ' を削除した場合。
http://localhost:8080/Sandbox/Test
ウェブ初期化子
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] { WebApplicationConfiguration.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/Page/" };
}
@Override
protected String getServletName() {
return "dispatcher";
}
}
WebApplicationConfiguration
@EnableWebMvc
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration
@ComponentScan(basePackages = {"com.myapp.sandbox.business",
"com.myapp.sandbox.page",
"com.myapp.sandbox.utility"})
public class WebApplicationConfiguration extends WebMvcConfigurerAdapter {
/**
* Defines a {@link ViewResolver} as a Spring managed bean.
*
* @return the viewResolver
*/
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/page");
resolver.setSuffix(".jsp");
return resolver;
}
/**
* Registers resource handlers with Spring.
*
* @param registry the {@link ResourceHandlerRegistry}
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/view/**").addResourceLocations("/view/");
}
}
TestController
私はあなたがreturn new String[] { "/Page/" };
と最初の文字を使用するので、あなたの問題は、これらのライン
resolver.setPrefix("/WEB-INF/page");
であることを考える
あなたは詳しく説明できますか?サーブレットマッピングはInternalResourceViewResolverに関連していますか? – Mostfoolish