A standard WebLogic Server installation provides standard Java EE 5 dependency injection (DI) and interceptors (a form of aspect-oriented programming) in the WebLogic Server Java EE container. WebLogic Server also supports a Spring Framework extension that provides enhanced dependency injection and aspect-oriented programming features in the container. This extension uses Pitchfork, a Spring Framework add-on that provides JSR-250 (Common Annotations), dependency injection, and EJB 3.0 style interception. (See http://www.springsource.com/pitchfork
.) The extension provides dependency injection and aspect-oriented programming to EJB instances and Web components that include the servlet listener and filter.
Note:
JSP tag handlers do not support the Spring extension in this release of WebLogic Server.To enable the Spring extension with WebLogic Server, do the following:
Download a version of Spring and its dependencies from http://www.springsource.com/download
. Download the version of Spring that is certified by Oracle. For that information, follow the appropriate "Oracle WebLogic Server" link on the Oracle Fusion Middleware Supported System Configurations page at http://www.oracle.com/technology/software/products/ias/files/fusion_certification.html
You must have at least the following JAR files:
spring.jar
aspectjweaver.jar
commons-logging.jar
log4j-1.2.14.jar
pitchfork.jar
Also download pitchfork.jar
from http://www.springsource.com/pitchfork
You can add other JAR files if necessary.
Add the JARs listed above to the WebLogic Server classpath. See Adding JARs to the System Classpath in Oracle Fusion Middleware Developing Applications for Oracle WebLogic Server.
The WebLogic Server Web container and EJB container use these JARs to provide container services (dependency injection and interceptor).
Applications (packaged as EAR, WAR, or JAR files) can use these JARs because they are in the server classpath. You can configure your application to use the version of JARs packaged with the application if you enable certain of the deployment descriptors.
Enable the Spring extension by setting the <component-factory-class-name>
element to org.springframework.jee.interfaces.SpringComponentFactory
. This element exists in EJB, Web, and application descriptors. A module level descriptor overwrites an application level descriptor. If the tag is set to null (default), the Spring extension is disabled.
Provide the standard Spring bean definition file with the name spring-ejb-jar.xml
or spring-web.xml
, and place it in the /WEB-INF/classes/META-INF directory of your application (or put the META-INF directory in a JAR file). These are the standard Spring bean definition files with the names that the Weblogic container searches for. For the Spring container to be aware of the EJB or servlet instance, the <id>
tag of the Spring bean must be set to the ejb-name
for EJB or the class-name
of the Web components.
For example, for the following stateless EJB...
@Stateless public class TraderImpl implements Trader { private List symbolList; public void setSymbolList(List l) { symbolList = l; } ... }
...you can add the following spring-ejb-jar.xml
to the application...
<beans> <!-- id corresponds to ejb-name. --> <bean id="Trader"> <property name="symbolList"> <list> <value>ORCL</value> <value>MSFT</value> </list> </property> </beans>
...to inject a symbolList
to the EJB, which is not available using the standard Java EE specification.