Tapestry/Spring Integration

http://tapestry.apache.org/tapestry5/tapestry-spring/

Provides integration between Tapestry and Spring, allowing beans defined by Spring to be injected into Tapestry IoC services, and into Tapestry components.

Changes From 5.0

You may now use the @Inject or @InjectService annotations inside Spring beans; these will be resolved to Tapestry services or other objects available via the MasterObjectProvider. Please see the detailed guide to Injection .

The dependency on Spring is no longer scope "provider" and has changed to 2.5.6.

Spring Beans are no longer exposed as services, unless 5.0 compatibility mode is enabled.

You no longer create a ContextLoaderListener.

These changes represent an unfortunate backwards compatibility issue. If necessary, you can still use tapestry-spring version 5.0.18 with the rest of Tapestry.

Spring Version

This module is compiled and tested against Spring 2.5.6. It should be resonable to override the dependency to earlier versions of Spring, though the code makes use of some APIs that were added to Spring to support JDK 1.5 annotations.

Usage

The integration is designed to be a very thin layer on top of Spring's normal configuration for a web application.

Detailed instructions are available in the Spring documentation . Please omit the part about creating a ContextLoaderListener: this is now done automatically by Tapestry.

web.xml changes

The short form is that you must make two small changes to your application's web.xml.

First, a special filter is used in replace of the standard TapestryFilter:

  <filter>
<filter-name>app</filter-name>
<!-- Special filter that adds in a T5 IoC module derived from the Spring WebApplicationContext. -->
<filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter>

Secondly, you may add the normal Spring configuration, consisting of an optional <context-param> identifying which Spring bean configuration file(s) to load:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>

The <context-param> lists the Spring bean configuration file. It is optional and defaults to just /WEB-INF/applicationContext.xml if omitted.

Injecting beans

Inside your component classes, you may use the Inject annotation. Typically, just the field type is sufficient to identify the Spring bean to inject:

  @Inject
private UserDAO userDAO;

Searching for Spring beans is threaded into the MasterObjectProvider service . The Spring context becomes one more place that Tapestry searches when determining the injection for a injected field or method parameter.

ApplicationContext Service

The Spring ApplicationContext is also added as a service.

ApplicationContextCustomizer

A new chain-of-command service, ApplicationContextCustomizer allows the application context, created by Tapestry, to be customized as it is created. You may contribute your own ApplicationContextCustomizer instances as needed.

5.0 Compatibility Mode

In some circumstances, it is desirable to configure the Spring ApplicationContext externally. The context <config-param> "tapestry.use-external-spring-context" can be configured to "true". Tapestry will then use an existing ApplicationContext, provided by a Spring ContextLoaderListener. You will still be able to inject Spring beans into Tapestry components and services, and the ApplicationContext service will be visible ... but you will not be able to inject Tapestry IoC services into Spring beans.

This option provides compatibility with the tapestry-spring 5.0, including exposing Spring beans as Tapestry IoC services (something that no longer occurs unless compatibility mode is enabled).

Limitations

Non-singleton beans are not handled properly. Tapestry will request the beans from the application context in a manner unsuitable for their lifecycle. For the moment, you should consider the non-singleton beans to be not-injectable. Instead, inject the ApplicationContext service and obtain the non-singleton beans as needed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值