SSH integration (struts2.2.1 + spring3.0 + hibernate3.3)
01. Version: struts2.2.1 + spring3.0 + hibernate3.3
02. MyEclipse8.6 introduces the JAR package
03.
04.1. Introduces the JAR package:
05.a) You can use the function that comes with myeclipse to import the required package:
06. Right-click the project --> MyEclipse--> add Hibernate capabilities, add spring capabilities
07.
08.b) The package of struts2 can be copied from the downloaded directory. There are seven packages
09. For example: E:/CL/API/struts-2.2 .1.1-all/struts-2.2.1.1/apps/struts2-blank/WEB-INF/lib
10.
11.c) Also need plugin package struts2-spring-plugin-2.2.1.1.jar
12. For example: E:/ CL/API/struts-2.2.1.1-all/struts-2.2.1.1/lib
13.
14.
15.
16.2. Configuration file: (mainly the configuration of web.xml and applicationContext.xml)
17.
18.web.xml :
19.
20. <filter>
21. <filter-name>struts2</filter-name>
22. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
23. </filter>
24.
25. <filter-mapping>
26. <filter-name>struts2</filter-name>
27. <url-pattern>/*</url-pattern>
28. </filter-mapping>
29.
30. <context-param>
31. <param-name>contextConfigLocation</param-name>
32. <param-value>classpath:applicationContext.xml</param-value>
33. </context-param>
34.
35. <listener>
36. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
37. </listener>
38.
39.
40.applicationContext.xml:
41.
42.<beans xmlns="http://www.springframework.org/schema/beans"
43. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
44. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
45. xsi:schemaLocation="http://www.springframework.org/schema/beans
46. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
47. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
48. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
49. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
50.
51. <!-- 支持元注释 -->
52. <context:annotation-config />
53.
54. <!-- 扫描包目录 -->
55. <context:component-scan base-package="com"></context:component-scan>
56.
57. <bean id="sessionFactory"
58. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
59. <property name="configLocation" value="classpath:hibernate.cfg.xml">
60. </property>
61. </bean>
62.
63. <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
64. <property name="sessionFactory">
65. <ref bean="sessionFactory" />
66. </property>
67. </bean>
68.</beans>
69.
70.
71.hibernate.cfg.xml:
72.
73. <!DOCTYPE hibernate-configuration PUBLIC
74. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
75. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
76.
77. <hibernate-configuration>
78.
79. <session-factory>
80. <property name="dialect">
81. org.hibernate.dialect.Oracle9Dialect
82. </property>
83. <property name="connection.url">
84. jdbc:oracle:thin:@localhost:1521:oracle
85. </property>
86. <property name="connection.username">chenl</property>
87. <property name="connection.password">chenl</property>
88. <property name="connection.driver_class">
89. oracle.jdbc.driver.OracleDriver
90. </property>
91.
92. <!--
93. <mapping resource="com/po/TUser.hbm.xml" />
94. <mapping resource="com/po/TDetail.hbm.xml" />
95. -->
96. </session-factory>
97.
98. </hibernate-configuration>
99.
100.
101.struts.xml:
102. <!DOCTYPE struts PUBLIC
103. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
104. "http://struts.apache.org/dtds/struts-2.0.dtd">
105.
106. <struts>
107. <constant name="struts.enable.DynamicMethodInvocation" value="false" />
108. <constant name="struts.devMode" value="true" />
109. <package name="user" extends="struts-default" namespace="/user">
110. <action name="user" class="com.jungle.action.UserAction">
111. </action>
112. </package>
113. </struts>
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326861324&siteId=291194637
Recommended
Ranking