Example of ssh framework integration-configuration file
The main configuration file is as follows:
1. web. xml:
Configure actionservlet class and ing
Configure Listener and load spring Configuration
<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4"
Xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>
<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>
<Servlet>
<Servlet-name> action </servlet-name>
<Servlet-class>
Org. apache. struts. action. ActionServlet
</Servlet-class>
<Init-param>
<Param-name> config </param-name>
<Param-value>
/WEB-INF/struts-config.xml
</Param-value>
</Init-param>
<Load-on-startup> 0 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> action </servlet-Name>
<URL-pattern> *. DO </url-pattern>
</Servlet-mapping>
<Welcome-file-List>
<Welcome-File> index. jsp </welcome-File>
</Welcome-file-List>
</Web-app>
2. struts-config.xml
<? XML version = "1.0" encoding = "ISO-8859-1"?>
<! Doctype Struts-config public
"-// Apache Software Foundation // DTD struts configuration 1.3 // en"
Http://struts.apache.org/dtds/struts-config_1_3.dtd>
<Struts-config>
<Form-beans>
<Form-bean name = "userform"
Type = "com. Yanek. Demo. Ssh. Bean. userform">
</Form-bean>
</Form-beans>
<Global-forwards>
<Forward name = "error" Path = "/error. jsp"> </forward>
</Global-forwards>
<Action-mappings>
<! --
<Action Path = "/user" name = "userform"
Type = "com. Yanek. Demo. Ssh. Action. useraction"
Scope = "request" Validate = "true" input = "/register. jsp">
<Forward name = "success" Path = "/reg_success.jsp"/>
</Action>
-->
<Action path = "/user" name = "userForm"
Type = "org. springframework. web. struts. DelegatingActionProxy"
Scope = "request" validate = "false" input = "/register. jsp"
Parameter = "method">
<Forward name = "success" path = "/reg_success.jsp"/>
<Forward name = "list" path = "/list. jsp"/>
</Action>
</Action-mappings>
<Message-resources parameter = "ApplicationResources"/>
</Struts-config>
3. applicationContext. xml
<? Xml version = "1.0" encoding = "UTF-8"?>
<Beans xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.0.xsd>
<! -- Define a data source -->
<Bean id = "dataSource"
Class = "org. springframework. jdbc. datasource. DriverManagerDataSource"
Destroy-method = "close">
<! -- Specify the database connection driver -->
<Property name = "driverClassName"
Value = "com. microsoft. jdbc. sqlserver. SQLServerDriver"/>
<! -- Specify the url to connect to the database -->
<Property name = "url"
Value = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = ssh"
/>
<! -- Specify the username used to connect to the database. The password is null. -->
<Property name = "username" value = "sa"/>
<Property name = "password" value = ""/>
</Bean>
<! -- Define sessionfactory of hibernate -->
<Bean id = "sessionfactory"
Class = "org. springframework. Orm. hibernate3.localsessionfactorybean">
<! -- Specify the data source -->
<Property name = "datasource" ref = "datasource"/>
<! -- Specify the hibernate ing file -->
<Property name = "mappingresources">
<List>
<Value> COM/Yanek/demo/ssh/Vo/user. HBM. xml </value>
</List>
</Property>
<Property name = "hibernateproperties">
<Props>
<! -- Specify the Dialect -->
<Prop key = "hibernate. dialect">
Org. hibernate. dialect. sqlserverdialect
</Prop>
<! -- Whether to output SQL statements on the console -->
<Prop key = "show_ SQL"> true </prop>
<Prop key = "hibernate. hbm2ddl. Auto"> Update </prop>
<Prop key = "hibernate. JDBC. batch_size"> 20 </prop>
</Props>
</Property>
</Bean>
<! -- Define Transaction Management -->
<Bean id = "transactionmanager"
Class = "org. springframework. Orm. hibernate3.hibernatetransactionmanager">
<Property name = "sessionFactory" ref = "sessionFactory"/>
</Bean>
<! -- Define the transaction management interceptor -->
<Bean id = "transactionInterceptor"
Class = "org. springframework. transaction. interceptor. TransactionInterceptor">
<Property name = "transactionManager" ref = "transactionManager"/>
<Property name = "transactionAttributes">
<Props>
<Prop key = "get *"> PROPAGATION_REQUIRED, readOnly </prop>
<Prop key = "*"> PROPAGATION_REQUIRED </prop>
</Props>
</Property>
</Bean>
<! -- Define proxy to automatically manage transactions -->
<Bean id = "ProxyCreator"
Class = "org. springframework. AOP. Framework. autoproxy. beannameautoproxycreator">
<! -- Specify the bean that requires spring to manage transactions -->
<Property name = "beannames">
<List>
<Value> userservice </value>
</List>
</Property>
<! -- Call the transaction management interceptor -->
<Property name = "interceptornames">
<List>
<Value> transactioninterceptor </value>
</List>
</Property>
</Bean>
<! -- Inject Dao to the session factory -->
<Bean id = "userdao" class = "com. Yanek. Demo. Ssh. Dao. userdaoimpl">
<Property name = "sessionfactory">
<Ref local = "sessionfactory"/>
</Property>
</Bean>
<! -- Inject service to Dao -->
<Bean id = "userservice"
Class = "com. Yanek. Demo. Ssh. Service. userserviceimpl">
<Property name = "userdao" ref = "userdao"> </property>
</Bean>
<! -- Inject action to service -->
<Bean name = "/user"
Class = "com. Yanek. Demo. Ssh. Action. useraction">
<Property name = "userservice" ref = "userservice"> </property>
</Bean>
</Beans>