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會找到,但無法檢測到資源的位置。 我不知道更多。 請幫忙
我想你需要使用'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