Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Name

My Plugin

Author

Donald Brown

Homepage

http://localhost/myplugin

Version

1.0

Compatibility

Struts 2.0.2+

State

Unstable

License

Open Source (ASL2)

Download

http://localhost/myplugin/download

Overview

Excerpt

The Spring plugin allows Actions, Interceptors, and Results to be created and/or autowired by Spring.

...

Note
titleSpring Actions are Optional!

Remember: registering Actions with Spring is not required. The Spring alternative is there if you need it, but the framework will automatically create Actions objects from the action mappings. But, if you want to use Spring to inject your Actions, the option is there.

Features

  • Allow Actions, Interceptors, and Results to be created by Spring
  • Struts-created objects can be autowired by Spring after creation
  • Provides two interceptors that autowire actions, if not using the Spring ObjectFactory

Usage

To enable Spring integration, simply include struts2-spring-plugin-x-x-x.jar in your application.

...

Code Block
titlestruts.properties
struts.objectFactory = spring

Autowiring

The framework enables "autowiring" by default. (Autowiring means to look for objects defined in Spring with the same name as your object property). To change the wiring mode, modify the spring.autowire property.

...

Tip
titleMore applicationContext configuration files needed?

Since the Spring integration uses a standard Listener, it can be configured to support configuration files other than applicationContext.xml. Adding the following to your web.xml will cause Spring's ApplicationContext to be inititalized from all files matching the given pattern:

Code Block
xml
xml
<!-- Context Configuration locations for Spring XML files -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>

See the Spring documentation for a full description of this parameter.

Initializing Actions from Spring

Normally, in struts.xml you specify the class for each Action. When using the default SpringObjectFactory, the framework will ask Spring to create the Action and wire up dependencies as specified by the default auto-wire behavior.

...

Code Block
xml
xml
titleapplicationConext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
    <bean id="bar" class="com.my.BarClass" singleton="false"/>
    ...
</beans>

Settings

The following settings can be customized. See the developer guide.

Setting

Description

Default

Possible Values

struts.objectFactory.spring.autoWire

The autowire strategy

name

name,type,auto, or constructor

struts.objectFactory.spring.useClassCache

Whether to have Spring use its class cache or not

true

true or false

Installation

This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. No other files need to be copied or created.