2013-02-12 125 views
1

听到我有一个问题让MVC 3和瓷砖一起工作
基于Java的web配置与Spring MVC的3和瓷砖

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.*; 
    import org.springframework.web.servlet.view.tiles2.TilesConfigurer; 
    import org.springframework.web.servlet.view.tiles2.TilesViewResolver; 

    @Configuration 
    @EnableWebMvc 
    @ComponentScan(basePackages = {"foo"}) 
    public class WebMvcConfig extends WebMvcConfigurationSupport { 

    @Override 
    public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) { 
     configurer.enable(); 
    } 

} 


和...

@Configuration 
    public class ViewConfiguration { 
     @Bean 
     public TilesConfigurer tilesConfigurer() { 
     return new TilesConfigurer(); 
    } 

    @Bean 
    public TilesViewResolver tilesViewResolver() { 
     TilesViewResolver tilesViewResolver = new TilesViewResolver(); 
     tilesViewResolver.setOrder(2); 
     return tilesViewResolver; 
    } 


和下面的瓷砖config

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!DOCTYPE tiles-definitions PUBLIC 
     "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" 
     "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> 


<tiles-definitions> 

    <definition name="mainLayout" template="/view/layout/layout.jsp"> 
     <put-attribute name="header" value="/view/layout/header.jsp"/> 
     <put-attribute name="menu" value="/view/layout/menu.jsp"/> 
     <put-attribute name="footer" value="/view/layout/footer.jsp"/> 
     <put-attribute name="body" value="/view//layout/body.jsp"/> 
    </definition> 
    <definition name="test" extends="mainLayout"> 
     <put-attribute name="body" value="/view/test.jsp"/> 
    </definition> 
</tiles-definitions> 

这里是我的测试控制器

@Controller 
public class TestController { 

    @RequestMapping("/hello") 
    public String helloWorld() { 
     return "test"; 
    } 
} 


这里是输出

DispatcherServlet.initContextHolders(986) | Bound request context to thread: [email protected]                                                
DispatcherServlet.doService(823) | DispatcherServlet with name 'dispatcher' processing GET request for [/trd/hello]                                                    
DispatcherServlet.getHandler(1088) | Testing handler map [org.springframework[email protected]eca5a40] in DispatcherServlet with name 'dispatcher'                                
RequestMappingHandlerMapping.getHandlerInternal(219) | Looking up handler method for path /hello                                                         
RequestMappingHandlerMapping.lookupHandlerMethod(263) | Found 1 matching mapping(s) for [/hello] : [{[/hello],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}]                                    
RequestMappingHandlerMapping.getHandlerInternal(226) | Returning handler method [public java.lang.String ir.parsdeveloper.web.controller.TestController.helloWorld()]                                       
DefaultListableBeanFactory.doGetBean(246) | Returning cached instance of singleton bean 'testController'                                                       
DispatcherServlet.getHandlerAdapter(1122) | Testing handler adapter [org.springframework[email protected]6eb2756]                                         
DispatcherServlet.doDispatch(912) | Last-Modified value for [/trd/hello] is: -1                                                             
HandlerMethod.invokeForRequest(129) | Invoking [helloWorld] method with arguments []                                                            
HandlerMethod.invokeForRequest(135) | Method [helloWorld] returned [test]                                                              
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web.ser[email protected]2903ccd9] supports [class java.lang.String]                      
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [[email protected]87dcf98] supports [class java.lang.String]                             
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework[email protected]4bc82121] supports [class java.lang.String]                        
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframew[email protected]3ff72465] supports [class java.lang.String]                        
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web[email protected]5979da9f] supports [class java.lang.String]                       
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web.servl[email protected]4f002a9d] supports [class java.lang.String]                     
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web.[email protected]6271edc8] supports [class java.lang.String]                      
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.spri[email protected]4f432acf] supports [class java.lang.String]                          
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web.s[email protected]468f7aa2] supports [class java.lang.String]                      
HandlerMethodReturnValueHandlerComposite.getReturnValueHandler(78) | Testing if return value handler [org.springframework.web[email protected]5522a7b5] supports [class java.lang.String]                       
DispatcherServlet.render(1206) | Rendering view [org.springframework.web.servlet.view.tiles2.TilesView: name 'test'; URL [test]] in DispatcherServlet with name 'dispatcher'                                      
TilesView.render(257) | Rendering view with name 'test' with model {} and static attributes {}                                                         
DefaultListableBeanFactory.getBeanDefinition(566) | No bean named 'requestDataValueProcessor' found in org.springframework.beans.factory.support.Defa[email protected]: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,webMvcConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,viewConfiguration,testController,tilesConfigurer,tilesViewResolver,org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration,requestMappingHandlerMapping,mvcContentNegotiationManager,viewControllerHandlerMapping,beanNameHandlerMapping,resourceHandlerMapping,defaultServletHandlerMapping,requestMappingHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver]; root of factory hierarchy 
BasicTilesContainer.render(615) | Render request recieved for definition 'test'                                                             
DispatcherServlet.initContextHolders(986) | Bound request context to thread: [email protected]                                                
DispatcherServlet.doService(823) | DispatcherServlet with name 'dispatcher' processing GET request for [/trd/view/thirdParty/layout/layout.jsp]                                             
DispatcherServlet.getHandler(1088) | Testing handler map [org.springframework[email protected]eca5a40] in DispatcherServlet with name 'dispatcher'                                
RequestMappingHandlerMapping.getHandlerInternal(219) | Looking up handler method for path /view/thirdParty/layout/layout.jsp                                                  
RequestMappingHandlerMapping.getHandlerInternal(229) | Did not find handler method for [/view/thirdParty/layout/layout.jsp]                                                  
DispatcherServlet.getHandler(1088) | Testing handler map [or[email protected]696911f6] in DispatcherServlet with name 'dispatcher'                                    
BeanNameUrlHandlerMapping.getHandlerInternal(127) | No handler mapping found for [/view/thirdParty/layout/layout.jsp]                                                   
DispatcherServlet.getHandler(1088) | Testing handler map [org.springframework.web.servlet.c[email protected]10f98160] in DispatcherServlet with name 'dispatcher'                             
DispatcherServlet.getHandler(1088) | Testing handler map [org.springframework.web.servlet.c[email protected]6c9cce54] in DispatcherServlet with name 'dispatcher'                             
DispatcherServlet.getHandler(1088) | Testing handler map [org.springframework.web.servlet.c[email protected]2aae2481] in DispatcherServlet with name 'dispatcher'                             
ageNotFound.noHandlerFound(1108) | No mapping found for HTTP request with URI [/trd/view/thirdParty/layout/layout.jsp] in DispatcherServlet with name 'dispatcher'                                        
DispatcherServlet.resetContextHolders(996) | Cleared thread-bound request context: [email protected]                                              
DispatcherServlet.processRequest(951) | Successfully completed request                                                               
AnnotationConfigWebApplicationContext.publishEvent(332) | Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/trd/view/thirdParty/layout/layout.jsp]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[804ms]; status=[OK] 
DispatcherServlet.resetContextHolders(996) | Cleared thread-bound request context: [email protected]b4c72c8                                               
DispatcherServlet.processRequest(951) | Successfully completed request                                                               
AnnotationConfigWebApplicationContext.publishEvent(332) | Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/trd/hello]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[7716ms]; status=[OK]       

我知道,控制器正常工作propelry并返回“测试”作为输出 但是当春天去寻找鉴于有一些问题。 我认为/trd/view/layout/layout.jsp会找到,但无法检测到资源的位置。 我不知道更多。 请帮忙

+0

我想你需要使用'setDefinitions(String [] definitions)'来设置TilesConfigurer的定义。您需要传递一个字符串数组,告诉它在哪里找到tiles xml配置。通常瓷砖模板是jspx,我不确定这是否会有所作为。通过使用Spring Roo,您可以看到一个示例spring + tiles项目:在STS(Springsource Tools Suite)上创建一个新的Spring Roo项目,并为其命名,并在roo shell上运行命令web mvc setup。 – gerrytan 2013-02-12 21:48:15

回答

3

你需要告诉你的瓷砖配置在哪里可以找到定义文件。您可以执行new TilesConfigurer().setCompleteAutoload(true);这可启用完整的自动加载功能,该功能将通过您的WEB-INF文件夹查找任何以-definitions.xml结尾的定义文件或明确指向文件new TilesConfigurer().setDefinitions("path/to/defitions.xml");