- 浏览: 1098548 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
skyesx:
这是2PC实现,更常用的是一个柔性事务的实现,可以参考http ...
Spring分布式事务实现 -
ddbird:
这第一句就不严谨“分布式事务是指操作多个数据库之间的事务”,显 ...
Spring分布式事务实现 -
呵呵6666:
基于互联网支付系统的微服务架构分布式事务解决方案http:// ...
Spring分布式事务实现 -
小黄牛:
写得不错,交流群:472213887
Spring分布式事务实现 -
jiaoqf321456:
这明明是用的apache的压缩,给ant.jar有半毛钱关系吗 ...
使用ant.jar进行文件zip压缩
How can you reference Spring beans from Tapestry 4? In earlier versions of Tapestry,
the most common method was to extend the BaseEngine class. However, in Tapestry 4 the BaseEngine class is deprecated, and we now need to extend SpringBeanFactoryHolder.
(Basic knowledge of Java, Tapestry, and Spring assumed.)
Step 1: Hivemind Configuration
Note: You can skip this step by downloading tapestry-spring.jar from http://sourceforge.net/projects/diaphragma and placing it on your classpath.
Continue reading, if you're interested in how it works...
Tapestry uses Hivemind, behind the scenes, for dependency-injection. Hivemind's XML configuration is similar to Spring. The easiest way to contribute to the whole Hivemind registry is by creating hivemodule.xml in your WEB-INF directory.
Here is what you need in this project to provide a new implementation of the DefaultSpringBeanFactoryHolder:
程序代码: |
<?xml version="1.0"?> <module id="diaphragma.tapspr" version="1.0.0"> <implementation service-id="hivemind.lib.DefaultSpringBeanFactoryHolder"> <invoke-factory> <construct autowire-services="false" class="diaphragma.tapspr.XSpringBeanFactoryHolderImpl"> <event-listener service-id="hivemind.ShutdownCoordinator" /> <set-object property="context" value="service:tapestry.globals.WebContext" /> </construct> </invoke-factory> </implementation> </module> |
Next job is to create XSpringBeanFactoryHolderImpl.java. It look like this:
程序代码: |
package diaphragma.tapspr; import java.io.PrintStream; import org.apache.hivemind.events.RegistryShutdownListener; import org.apache.hivemind.lib.impl.SpringBeanFactoryHolderImpl; import org.apache.tapestry.web.WebContext; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.ConfigurableApplicationContext; public class XSpringBeanFactoryHolderImpl extends SpringBeanFactoryHolderImpl implements RegistryShutdownListener { private WebContext context; public XSpringBeanFactoryHolderImpl() { } public void setContext(WebContext webcontext) { context = webcontext; } public WebContext getContext() { return context; } public BeanFactory getBeanFactory() { if(super.getBeanFactory() == null) super.setBeanFactory(XWebApplicationContextUtils.getWebApplicationContext(getContext())); return super.getBeanFactory(); } public void registryDidShutdown() { ((ConfigurableApplicationContext)super.getBeanFactory()).close(); } } |
As we can see, this class extends the default SpringBeanFactoryHolder. The important thing is what you see in getBeanFactory() method, there you define where our BeanFactory located. In this example, I use WebApplicationContextUtils.getRequiredWebApplicationContext() method. There is another method which doesn't throw exception WebApplicationContextUtils.getWebApplicationContext().
Next, we implement XWebApplicationContextUtils.java
程序代码: |
package diaphragma.tapspr; import org.apache.tapestry.web.WebContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class XWebApplicationContextUtils extends WebApplicationContextUtils { public XWebApplicationContextUtils() { } public static WebApplicationContext getWebApplicationContext(WebContext webcontext) { Object obj = webcontext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if(obj == null) return null; if(obj instanceof RuntimeException) throw (RuntimeException)obj; if(obj instanceof Error) throw (Error)obj; if(!(obj instanceof WebApplicationContext)) throw new IllegalStateException((new StringBuilder()).append("Root context attribute is not of type WebApplicationContext: ").append(obj).toString()); else return (WebApplicationContext)obj; } public static WebApplicationContext getRequiredWebApplicationContext(WebContext webcontext) throws IllegalStateException { WebApplicationContext webapplicationcontext = getWebApplicationContext(webcontext); if(webapplicationcontext == null) throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?"); else return webapplicationcontext; } } |
Step 2: Spring Configuration
Spring in servlet mode need two things, it needs the XML file for bean configuration and also a filter in web.xml. In web.xml, you will have to add this:
程序代码: |
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> |
And now let us try a simple XML file (place it under WEB-INF/ as applicationContext.xml).
程序代码: |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans public "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="person" class="com.example.model.Person"> <property name="name"> <value>Nanda Firdausi</value> </property> </bean> </beans> |
It defines one object with one property.
Step 3: Access Spring property from Tapestry page specification
Now time to see whether our bean can be accessed from a Tapestry page. First, let us create the page specification (Home.page).
程序代码: |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN" "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd"> <page-specification class="org.apache.tapestry.html.BasePage"> <inject property="person" object="spring:person" /> </page-specification> The page template is trivial, one super-simple-example is like this (Home.html). <span jwcid="@Insert" value="ognl:person.name" /> Please make comments, suggestions, and any other things related to this tutorial. |
--------------------------------------------------------------------------------
This information was originally written in an email to the Tapestry User's List on March 7, 2005 by Nanda Firdausi
HowardLewisShip: This is pretty much overkill, since you can just acquire your AC and store it into the DefaultSpringBeanFactoryHolder service with no additional work. I do like that you have a shutdown option, though. I'm putting together a proper implementation for Tapestry @ JavaForge.
HowardLewisShip: I've put together a basic Spring integration module: tapestry-spring. The solution on this page is a little more flexible, however (at least for the moment).
NandaFirdausi: I've seen your implementation, and I like it too, just like your other code ;). I thing your implementation doesn't need spring listener anymore, am I right? If so, then the choice to the user is if they do have another spring wep application with nothing to do with tapestry, it's better to set the spring listener and do like this page says. If your web application is all tapestry based (with spring as back-end support), then your code looks cleaner for me
Tapestry 4 (another solution)
JarekWoloszyn: Here is another solution for Tapestry4.
We need a helper class which will create WebApplicationContext for the ServletContext. Hivemind can't call factory methods (from WebApplicationContextUtils), so we create a POJO. Spring Context is re-created everytime we change ServletContext.
程序代码: |
package org.your.application; import javax.servlet.ServletContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class SpringContextFactory { private ServletContext servletContext; private WebApplicationContext appContext; public WebApplicationContext getAppContext() { return appContext; } public ServletContext getServletContext() { return servletContext; } public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; appContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); } } |
Tapestry 4 has Spring integration out of the box. We must only say which BeanFactory should be used. In hivemind.xml, we define a service-point for our helper class. This class takes ServletContext as parameter. We configure then Hivemind to use appContext member as spring-bean factory.
程序代码: |
<?xml version="1.0"?> <module id="app" version="1.0.0" package="org.your.application"> <contribution configuration-id="hivemind.ApplicationDefaults"> <default symbol="hivemind.lib.spring-bean-factory" value="service-property:app.SpringContextFactory:appContext"/> </contribution> <service-point id="SpringContextFactory"> Create WebApplicatonContext for Spring <invoke-factory> <construct class="SpringContextFactory"> <set-service property="servletContext" service-id="tapestry.globals.ServletContext"/> </construct> </invoke-factory> </service-point> </module> |
发表评论
-
JSF2之模板和复合组件
2010-03-03 17:19 4017模板和复合组件是 Java™Server Faces ... -
JSF2与Spring集成
2010-03-03 09:43 3473一、配置部分 1、applicationContext.xml ... -
关于JSF2.0(Java™Server Faces 2.0)
2010-03-01 09:58 8052一、资源 (1)JSF主页: https://ja ... -
wicket之实现IDataProvider接口,只查询当前页数据
2009-02-21 17:17 31231.html文件 <html> <he ... -
tapestry5.0之页面组件定义/页间传值/Application State Object
2009-02-18 13:04 3642一、页面组件定义方式 1.在模板(tml)文件中明确定义 &l ... -
tapestry5.0之Grid
2009-02-17 16:55 33561.tml文件 <t:layout xmlns:t=& ... -
Tapestry5自定义组件
2009-02-11 12:27 5404一、普通组件 1.java文件 package com.log ... -
Maven2 + tapestry5.0.18 + spring2 + hibernate3.2
2009-02-10 09:49 2939用quickstart生成Tapestry架构,再进行相 ... -
重定义wicket分页组件PagingNavigator
2008-11-05 13:06 36411.Navigator.java package com. ... -
wicket1.3.5+spring2.5+hibernate3.2
2008-10-28 21:55 1919不喜欢Tapestry4要用hivemind,wicke ... -
Wicket 1.5和Tapestry 5比较
2008-10-24 16:59 29001.Build Tool 对于很多开发者来说,bu ... -
Tapestry4实现文件导出功能
2008-05-09 12:50 1497@InjectObject("service:tap ...
相关推荐
### 基于Tapestry+Spring+Hibernate框架的Web应用 #### 框架概述与整合 在当今的企业级Web应用开发中,选择合适的框架是确保应用性能、可维护性和扩展性的关键。Tapestry、Spring和Hibernate作为三个广受好评的...
4. **事务管理**: Spring 提供的事务管理功能可以与 Tapestry 结合,确保数据操作的一致性和完整性。 5. **配置**: 通过配置文件,可以轻松地设置 Spring 容器,同时定义 Tapestry 组件的属性。Spring 配置文件通常...
SpringBeanFactoryHolder是Tapestry 4中用于与Spring集成的关键接口,它允许你在Tapestry组件中直接访问和使用Spring管理的Bean。通过扩展这个类,我们可以实现将Spring的依赖注入到Tapestry组件中的功能。 2. **...
4. `src/main/webapp` - Web应用的资源目录,包括Tapestry的页面和模板文件,以及静态资源(CSS、JavaScript)。 5. 可能还会有测试相关的目录,如`src/test`,包含单元测试和集成测试代码。 这个整合源码项目对于...
在IT行业中,开发高效、可维护的Web应用程序是至关重要的,而Tapestry、Hibernate和Spring框架的结合使用,能够帮助我们实现这一目标。本文将深入探讨如何在实际项目中运用这三个技术,以及它们如何协同工作,以实现...
【Tapestry4+Spring+Hibernate 整合实例】 Tapestry4、Spring 和 Hibernate 是三个在Java Web开发中至关重要的框架。Tapestry4 是一个MVC(Model-View-Controller)框架,提供了一种声明式编程模型,使得开发者可以...
《Tapestry5.1+Spring2.5.6+Hibernate3.2.5构建的简单CURD程序解析》 在Web开发领域,利用成熟的技术框架进行应用搭建是常见的实践方式。本文将深入探讨如何使用Tapestry5.1、Spring2.5.6和Hibernate3.2.5这三个...
tapestry-spring-5.2.6.jar,java spring框架依赖,可以直接使用
在Java Web开发领域,TSH(Tapestry、Spring、Hibernate)是一种常见的技术栈组合,用于构建高效、灵活且易于维护的Web应用。TSH结合了Tapestry的强大组件模型,Spring的依赖注入和事务管理,以及Hibernate的对象...
Tapestry是一个基于控件的框架以致于用它开发Web应用类似开发传统的GUI应用。你用Tapestry开发Web应用时你无需关注以操作为中心的(Operation-centric) Servlet API.引用Tapestry网站上的一句话:"Tapestry用对象...
Tapestry4与Hivemind的结合,虽然在最初可能会引发一些争议,尤其是对于那些习惯于Spring框架的开发者,但深入理解和使用后,你会发现Hivemind在依赖注入(IoC)和控制反转(DI)方面提供了简洁的解决方案。...
【标题】"Tapestry+Hibernate+Spring 整合应用示例" 【正文】 Tapestry、Hibernate 和 Spring 是三个在 Java Web 开发中非常关键的开源框架,它们各自在应用程序的不同层面上发挥着重要作用。Tapestry 是一个基于...
这是Tapestry5.3.8 版本的一个大Demo,集合Spring4.0, 采用Maven 项目管理工具,没有集合Hibernate。 之所以说是个大Demo,是因为这项目中包含的内容并不少,包含: 1)解决了Tapestry5.3.8中文Bug问题 2)Tapestry...
### Tapestry5 + Spring + Hibernate 开发指南 #### I. 引言 本文档旨在为初学者提供一个基于 Tapestry5、Spring 和 Hibernate 构建 Web 应用的基础指南。项目将通过一个简单的登录页面来展示如何整合这些技术。本...
在本文档中,我们将探讨如何将Tapestry与Spring框架集成,从而实现更高效的应用程序开发。Tapestry是一款强大的Java web应用程序框架,专注于组件化和动态页面生成,而Spring则是一个全面的企业级应用框架,提供了...
在本教程中,"Tapestry5First project with Tapestry5, Spring and Hibernate"将教你如何将这三个强大的框架整合到一个项目中。Tapestry5作为前端MVC框架,处理用户界面和交互;Spring则提供服务层和依赖注入,管理...
Tapestry可以与其他Java库和框架无缝集成,如Spring、Hibernate等,增强了其在大型项目中的适用性。 10. **学习资源**: 虽然Tapestry 4的中文文档较少,但提供的《Tapestry4 用户指南》和《Tapestry4 快速启动》...