我尝试在没有控制器方法的情况下映射切片定义,但是DispatcherServlet在没有控制器方法的情况下找不到定义。 例如:
进入tiles.xml
<tiles-definitions>
<definition name="/test" template="/WEB-INF/pages/dump/test.jsp">
</tiles-definitions>
如果我使用方法创建控制器,在这种情况下将显示页面:
@RequestMapping(value = {"/test"} , method = RequestMethod.GET)
public String indexAnonimous (){
return "/test";
}
如果我删除它,则DispatcherServlet找不到它。
我使用java配置。
WebApplicationInitializer:
public class ApplicationConfig implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setConfigLocation("com/ica/config");
rootContext.register(ApplicationContext.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);
characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
security.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
servletContext.addListener(new ContextLoaderListener(rootContext));
}
}
ApplicationContext.class - 我的应用程序上下文。
WebMVC:
@Configuration
@ComponentScan(basePackages = {"********"})
@EnableWebMvc
public class WebAppContext extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public ViewResolver viewResolver() {
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setViewClass(TilesView.class);
return viewResolver;
}
@Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setCheckRefresh(true);
tilesConfigurer.setDefinitions(new String[]{
"/WEB-INF/pages/tiles.xml"
});
return tilesConfigurer;
}
}
我没有控制器方法的日志
DEBUG [http-bio-8080-exec-7] (AntPathRequestMatcher.java:136) - Request '/test' matched by universal pattern '/**'
DEBUG [http-bio-8080-exec-7] (AbstractSecurityInterceptor.java:194) - Secure object: FilterInvocation: URL: /test; Attributes: [permitAll]
DEBUG [http-bio-8080-exec-7] (AbstractSecurityInterceptor.java:310) - Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@905571d8: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@0: RemoteIpAddress: 127.0.0.1; SessionId: D03A4E7DF41A3EF4AA8B1160678CED79; Granted Authorities: ROLE_ANONYMOUS
DEBUG [http-bio-8080-exec-7] (AffirmativeBased.java:65) - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@b3abed, returned: 1
DEBUG [http-bio-8080-exec-7] (AbstractSecurityInterceptor.java:215) - Authorization successful
DEBUG [http-bio-8080-exec-7] (AbstractSecurityInterceptor.java:227) - RunAsManager did not change Authentication object
[http-bio-8080-exec-7] (FilterChainProxy.java:323) - /test reached end of additional filter chain; proceeding with original chain
DEBUG [http-bio-8080-exec-7] (DispatcherServlet.java:845) - DispatcherServlet with name 'dispatcher' processing GET request for [/test]
DEBUG [http-bio-8080-exec-7] (AbstractHandlerMethodMapping.java:297) - Looking up handler method for path /test
DEBUG [http-bio-8080-exec-7] (AbstractHandlerMethodMapping.java:305) - Did not find handler method for [/test]
DEBUG [http-bio-8080-exec-7] (AbstractUrlHandlerMapping.java:169) - Matching patterns for request [/test] are [/**]
DEBUG [http-bio-8080-exec-7] (AbstractUrlHandlerMapping.java:194) - URI Template variables for request [/test] are {}
DEBUG [http-bio-8080-exec-7] (AbstractUrlHandlerMapping.java:124) - Mapping [/test] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@a866a8] and 1 interceptor
DEBUG [http-bio-8080-exec-7] (DispatcherServlet.java:931) - Last-Modified value for [/test] is: -1
DEBUG [http-bio-8080-exec-7] (HttpSessionSecurityContextRepository.java:304) - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
DEBUG [http-bio-8080-exec-7] (DispatcherServlet.java:1018) - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
DEBUG [http-bio-8080-exec-7] (FrameworkServlet.java:996) - Successfully completed request
DEBUG [http-bio-8080-exec-7] (ExceptionTranslationFilter.java:115) - Chain processed normally
DEBUG [http-bio-8080-exec-7] (SecurityContextPersistenceFilter.java:97) - SecurityContextHolder now cleared, as request processing completed
我可以使用另一个视图解析器,但它只适用于tile页面。 请建议我,没有控制器方法我应该做什么映射定义。