struts2過濾器 <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> <filter-mapping> 增加spring上下文配置 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> <context-param> 增加監聽器 <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listerner-class> </listener>
applicationContext.xml中數據源配置 可以換成其它的數據源 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 屬性驅動 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> 連接URL <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/> 用戶名 <property name="username" value="accp"/> 密碼 <property name="password" value="accp"/> </bean> 配置sessionFactory <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 關聯數據源 <property name="dataSource" ref="dataSource"/> 配置hibernate的屬性 <property name="hibernateProperties"> <props> 連接數據庫的方言這時視不同的數據和版本不同而定 <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> </props> </property> 映射文件配置 <property name="mappingResources"> <list> <value>實現類的hibernate配置文件路徑/類名.hbm.cfg</value> <value></value> </list> </property> </bean>
在applicationContext.xml中配置struts的action後
在struts.xml中action的class要寫applicationContext.xml中配置struts的action的id