spring mvc集成tiles的时候Tiles container is not initialized. Have you added a TilesConfigurer to your web application context
1.spring-MVC.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
default-lazy-init="true">
<!-- 自动扫描的包名 -->
<context:annotation-config />
<context:component-scan base-package="com.aliks.test.mvc.*" />
<bean id="filenameController"
class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
<!--UrlBasedViewResolver类 通过配置文件,把一个视图名交给到一个View来处理 -->
<bean id="jstlViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesResolver"
class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
<property name="order" value="1" />
<property name="viewNames">
<list>
<value>*</value>
</list>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
2.tiles.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name="index" template="/WEB-INF/layout/layout.jsp" >
<put-attribute name="title" value="hello tiles"></put-attribute>
<put-attribute name="head" value="head"></put-attribute>
<put-attribute name="menu" value="menu"></put-attribute>
<put-attribute name="content" value="/hello.html"></put-attribute>
<put-attribute name="footer" value="footer"></put-attribute>
</definition>
</tiles-definitions>
3.layout.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title><tiles:getAsString name="title" /></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table
style="margin: auto; border: 1px; border-style: solid; border-color: #ccc; width: 900px;">
<tr style="height: 100px; background-color: #555;">
<td colspan="2">
<%-- <tiles:insertAttribute name="head"></tiles:insertAttribute> --%>
<tiles:getAsString name="head" />
</td>
</tr>
<tr>
<td style="width: 200px; height: 500px; background-color: #666;">
<%-- <tiles:insertAttribute name="menu"></tiles:insertAttribute> --%>
<tiles:getAsString name="menu" />
</td>
<td><tiles:insertAttribute name="content"></tiles:insertAttribute>
</td>
</tr>
<tr style="height: 50px; background-color: #333;">
<td colspan="2">
<%-- <tiles:insertAttribute name="footer"></tiles:insertAttribute> --%>
<tiles:getAsString name="footer" />
</td>
</tr>
</table>
</body>
</html>
4.indexController的代码
package com.aliks.test.mvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/index")
public String IndexPage(Model model)
{
System.out.println("Tile index test");
return "index";
}
}
以上代码我个根据SpringMVC网络上的教材学着写的,过程中老是报异常,异常如下,找了很多资料都没有解决
六月 27, 2014 5:04:17 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet springMVC threw exception
javax.servlet.ServletException: Tiles container is not initialized. Have you added a TilesConfigurer to your web application context?
at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:102)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:744)
解决方法:主要是springMVC-servlet.xml配置问题
default-lazy-init="true"
导致了初始化的时候把Tiles加载到web application context中然到后没使用Tiles实力对象的时候找不到所以报异常了,去除这一行就OK了
分享到:
相关推荐
This book starts with an overview example and then explores each facet of a typical application by discussing simple snippets as they are added to a larger example. Along the way, you'll contrast ...
By the end of this book, you will have a good understanding of the new features added to Django 1.8 and be an expert at web development processes. What you will learn Get started with the basic ...
There is a default, so you don't need to define your own unless you wish to eliminate interactive messages and handle them on your own. This is helpful if you are using VCLZip as a service or on a ...
Source code + tutorial.<END><br>26 , chat.zip This code shows you how to creat a local network chat room so that you and your friends can have a chat room which nowone else can enter<END><br>27 , ...
used to bring a previously unleashed power and functionality to your Web pages. This book does assume that you have some working knowledge of HTML. You’ve probably created a few Web pages, perhaps ...
If you are a Java developer who has little or no experience in JEE application development or you have experience in JEE technology but are looking for tips to simplify and accelerate your development...
o Added 'Add' buttons, which allows you to easily add folders to scan or skip by choosing them from the list of Outlook folders. * Version 1.75 o Added the ability to choose the desired Outlook ...
This book will take you through a number of clear, practical recipes that will help you to take advantage of some readily available solutions. Boost C++ Application Development Cookbook starts out ...
This book is your authoritative hands-on practical guide for increasing your enterprise Java and cloud application productivity while decreasing development time. It's a no nonsense guide with case ...
There is apparently some malware going around that blocks execution of Cheat Engine (Saying file missing, ...you have been a victim of this then try this windows repair tool to fix your windows install...
When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could ...
would be a good idea to have a quick look at the demos. The library has been completely rewritten and a lot of new features has been added. ------------------------------------------- 4. Known ...
We have also added steps on how to create a demonstration application "ActiveSkill". These chapters leverage your knowledge from preceding sections to see how the controls are used together in a ...
It is still available, but our suggestion is that you try and model your farm designs first as a single web application and then use host header site collections in it. This is the model that we’ve ...
- The PBCanvas.dll assembly must be added to and distributed with your application. - There is no need to distribute canvas.pbx with your application. - You must remove and re-add the reference to ...