`
qkf15274
  • 浏览: 9297 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Have you added a TilesConfigurer to your web application context

阅读更多
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了

分享到:
评论

相关推荐

    Search Engine Marketing, Inc.: Driving Search Traffic to Your Company’s Web Site

    Find out how a little extra knowledge can send you on your way to help your customers find what they are looking for once they are on your Web site. The second edition also adds a companion DVD with...

    Manning - Play for Java 2014

    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 ...

    苹果AppStore 提交手册

    After you enroll in the program, you have access to all the resources and tools you need to manage your account and begin testing your app on a device. When you enroll, you become the primary contact...

    Web Development with Django Cookbook 2nd 2016第2版 epub格式

    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 ...

    Hands-On Dashboard Development with Shiny

    By the end of the book, you will have an understanding of the principles that underpin layout in Shiny applications, including sections of HTML added to a vanilla Shiny application, ...

    VclZip pro v3.10.1

    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 ...

    VB编程资源大全(英文源码 网络)

    Source code + tutorial.&lt;END&gt;&lt;br&gt;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&lt;END&gt;&lt;br&gt;27 , ...

    ASP Programming for the Absolute Beginner

    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 ...

    CoffeeScript.Accelerated.JavaScript.Development.2nd.Edition

    There's no faster way to learn to write a modern web application. This new edition has been extensively revised and updated to reflect the current state and features of CoffeeScript. Every chapter ...

    Easy Laravel5 A Hands On Introduction Usinga Real-World Project

    Just for added measure, I’ll walk you through the steps I took to incorporate a contact form into HackerPair, which when submitted, sends inquiring users’ messages and contact details to a support ...

    Java.EE.Development.with.Eclipse.2nd.Edition.178528534

    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...

    OutlookAttachView v2.73

    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 ...

    Take.My.Money.Accepting.Payments.on.the.Web.1680501992

    An e-commerce payment application is literally rewarding to build--you can see the return on investment as genuine money is added to your account. But it can be stressful to manage, with security and ...

    CE中文版-启点CE过NP中文.exe

    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...

    Senfore_DragDrop_v4.1

    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 ...

    RadControls for ASP.NET AJAX Courseware

     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 ...

    PBGUIControls.zip 最新版本2.7

    - 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 ...

    SSD7 选择题。Multiple-Choice

    Which of the following SQL statements can be used to add a row to a table? (a) CREATE (b) INSERT (c) APPEND (d) ADD Correct answer is (b) Your score on this question is: 10.00 ...

    search engine marketing

    Find out how a little extra knowledge can send you on your way to help your customers find what they are looking for once they are on your Web site. The second edition also adds a companion DVD with...

    Android代码-TourGuide

    Let's say you have a button on your home screen that you want your users to click on: Using TourGuide, the end result will look as below. A pointer, overlay and tooltip are added to the page to ...

Global site tag (gtag.js) - Google Analytics