========================================================== ======= Combined configuration of struts and spring frameworks ============================ ============================
To use spring as a plug-in for struts, add the following configuration to the struts-config.xml file:
<Plug-in classname = "org. springframework. Web. Struts. contextloaderplugin">
<Set-Property = "contextconfiglocation" value = "/WEB-INF/applicationcontext. xml"/>
</Plug-in>
Load spring in Web. XML in the following way
<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>
========================================================== ======= Combination of struts and spring in three ways ================================ ========================
1 ). Inherit from the org. springframework. Web. Struts. actionsupport class
Change the inheritance mode of the action class to org. springframework. Web. Struts. actionsupport or org. springframework. Web. Struts. dispatchactionsupport.
In the action class, you need to obtain spring context applicationcontext context = This. getwebapplicationcontext ();
2 ). Controller mode
You need to add to the struts-config.xml file:
<Controller processorclass = "org. springframework. Web. Struts. delegatingrequestprocessor">
</Controller>
In the applicationcontext. xml file, you must not only inject DAO implementation classes, but also inject action classes through the path of action classes.
3 ). Delegated proxy
In the struts-config.xml file, change the type attribute in the Action tag to org. springframework. Web. Struts. delegatinactionproxy.
Inject DAO implementation classes and actions in the applicationcontext. xml file in the same way as controller.
<! -Injection implementation class -->
<Bean name = "threeifc" class = "com. Soft. Test. testimp">
<Property name = "template" ref = "template"> </property>
</Bean>
<! -Inject action -->
<Bean name = "/Path" class = "com. Soft. Three. threeaction">
<Property name = "threeifc" ref = "threeifc"> </property>
</Bean>
========================================================== ======= Combination of The Hibernate framework and the Spring framework ============================ ==================
// The Hibernate configuration file is stored under SRC.
<Bean id = "sessionfactory" class = "org. springframework. Orm. hibernate3.localsessionfactorybean">
<Property name = "configlocation">
<Value> classpath: hibernate. cfg. xml </value>
</Property>
</Bean>
========================================================== ========= JDBC data source configuration ================================ ======================================
<Bean id = "datasource" class = "org. Apache. commons. DBCP. basicdatasource">
<Property name = "driverclassname">
<Value> oracle. JDBC. Driver. oracledriver </value>
</Property>
<Property name = "url">
<Value> JDBC: oracle: thin: @ 127.0.0.1: 1521: Name </value>
</Property>
<Property name = "username">
<Value> username </value>
</Property>
<Property name = "password">
<Value> password </value>
</Property>
</Bean>
========================================================== =========== Configure the JNDI data source ================================ ======================================
<Bean id = "datasource" class = "org. springframework. JNDI. jndiobjectfactorybean">
<Property name = "jndiname">
<Value> JAVA: COMP/ENV/jdbc/Oracle </value>
</Property>
</Bean>
<! -Hibernate parameter configuration -->
<Property name = "hibernateproperties">
<Props>
<Prop key = "hibernate. dialect"> <! -Database Dialect -->
Org. hibernate. dialect. oracle9dialect
</Prop>
<Prop key = "hibernate. show_ SQL"> <! -Print SQL statements on the console -->
True
</Prop>
</Props>
</Property>
<! -Table ing -->
<Property name = "mappingresources">
<List>
<Value> COM/webssh/tablename. HBM. xml </value>
</List>
</Property>
========================================================== =============== Hibernate template injection ================================== ======================================
<! -- Hibernatetemplate -->
<Bean name = "hibernatetemplate" class = "org. springframework. Orm. hibernate3.hibernatetemplate">
<Property name = "sessionfactory" ref = "sessionfactory"> </property>
</Bean>
There are two ways to use hibernatetemplate:
Method 1:
<! -- To inject a template to an interface, you need to write attributes in the implementation class -->
<Bean id = "classifc" class = "com. webssh. classinfo. classimp2">
<Property name = "template" ref = "hibernatetemplate"> </property>
</Bean>
Method 2:
<! -- Inject the template to the interface and do not need to write attributes in the implementation class -->
The interface must inherit the org. springframework. Orm. hibernate3.support. hibernatedaosupport class.
<Bean id = "classifc" class = "com. webssh. classinfo. classimp2">
<Property name = "hibernatetemplate" ref = "hibernatetemplate">
</Property>
</Bean>