Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the Integration of Webwork and Spring

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to analyze the integration of Webwork and Spring, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Here we use ActionAutowiringInterceptor, which is released with webwork2.2, to integrate Webwork with Spring.

1. Since the interceptor ActionAutowiringInterceptor is released with webwork2.2, this class is not included in webwork2.1.7. Fortunately, the address on the Internet is as follows:

Https://xwork-optional.dev.java.net/files/documents/1475/11992/spring-xwork-integration.jar . I also included this jar package in the attachment.

When you open the downloaded jar, you can see that there are only two packages inside, namely com.opensymphony.xwork.spring and com.opensymphony.xwork.spring.interceptor.

The ActionAutowiringInterceptor we need is just below the latter. I have seen the package structure of webwork-2.2, which also contains these two packages, but I tried to add the class files of these two packages to the xwork.jar of webwork2.1, but the result was an error. Using this separate package can complete the injection normally.

two。 After downloading the package, you need to add the package to your web application root directory lib folder, that is, under / WEB-INF/lib to complete the Webwork and Spring integration.

3. To modify the configuration file, you need to add an interceptor to xwork.xml as follows:

Java code

Org.springframework.beans.factory.config. AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE

There are four AUTOWIRE types defined in the AutowireCapableBeanFactory class. For more information, please refer to the api documentation of Spring.

The AUTOWIRE_BY_NAME type is used by default, which can be modified when configuring the listener.

After adding the interceptor, you can use the interceptor in the definition of action.

If you don't want to define this interceptor for every action, you can set it as the default interceptor. I modified the webwork-default.xml file directly, adding interceptors to the Webwork and Spring integration, and then adding the following declaration to each webwork configuration file.

Java code

Default-interceptor-ref >

4. After this configuration, you can use the IOC container provided by spring instead of the IOC container that comes with webwork. Of course, starting with webwork2.2, webwork's default IOC container has become Spring, and it does not provide the functionality of the IOC container itself. Maybe in order not to reinvent the wheel. This should also be possible in the webwork2.2 version, since the interceptor ActionAutowiringInterceptor was released with version 2.2.

5. The mechanism of this interceptor is that when the action in webwork needs a bean, the interceptor will go to the Context of Spring to find the bean, and then set the found bean to action according to the configuration of byName or other autowire methods.

Of course, action's own initialization is also delegated to Spring, and action is instantiated in scope=prototype.

Using interceptor to implement Webwork and Spring integration is a little more convenient and less configured than using SpringObjectFactory.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report