配置方法1: ***********************************web.xml******************************* <?xml version="1.0" encoding="UTF-8"?> <filter-mapping> **************************aplicationContext-common.xml***************************** <?xml version="1.0" encoding="UTF-8"?> <prop key="hibernate.show_sql">true</prop> <!--显示SQL语句--> **************************aplicationContext-bean.xml***************************** <?xml version="1.0" encoding="UTF-8"?> **************************aplicationContext-action.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" xmlns:aop=" http://www.springframework.org/schema/aop" xmlns:tx=" http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 此处的id="addAction" 必须与struts.xml中class="addAction"相一致--> <bean id=" addAction" class="com.bcm.action.AuthorAction" scope="prototype" > <property name="authorservice" ref="AuthorServiceImpl"></property> </bean> </beans>
*************************struts.xml***************************** <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC <constant name="struts.i18n.encoding" value="gbk"></constant> <action name="log" class="logAction" method="add">
备注:aplicationContext.xml文件 最好分为几个 如: * aplicationContext-common.xml (用于配置事务,数据源...) * aplicationContext-bean.xml(用于配置普通的类) * aplicationContext-action.xml(用于配置action) 配置方法2:将aplicationContext-common.xml 中的数据库配置交给hibernate.cfg.xml 。 修改如下: *****************************************aplicationContext-common.xml *********************** <?xml version="1.0" encoding="UTF-8"?> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> *********************************** hibernate.cfg.xml ******************************** <!DOCTYPE hibernate-configuration PUBLIC <hibernate-configuration> 注:所有的配置文件都在src目录下(除了web,xml) |
转载于:https://blog.51cto.com/cxh870510/376196