我这也在弄struts2 +srping3+hibernate4,但是我遇到问题不知道怎么配置,很多网上的例子都是annotation 形式的,看到你使用配置文件,希望你你能给我发一个demo
不胜感激
<!-- 配置数据源 -->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=svse"></property>
<property name="username" value="sa"></property>
<property name="password" value="svse"></property>
<property name="initialSize" value="2"></property>
<property name="maxActive" value="200"></property>
<property name="maxIdle" value="2"></property>
<property name="minIdle" value="1"></property>
</bean>
<!-- 配置sessionFactory 引入 *.hbm.xml-->
<bean name="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>com/morhweb/pojo/TUser.hbm.xml</value>
<value>com/morhweb/pojo/TUserAnnal.hbm.xml</value>
<value>com/morhweb/pojo/Ticket.hbm.xml</value>
<value>com/morhweb/pojo/TicketAnnal.hbm.xml</value>
<value>com/morhweb/pojo/OrderForm.hbm.xml</value>
</list>
</property>
<!-- 配置数据库方言 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- 配置一个事物管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 定义一个切面 -->
<aop:config>
<!-- 定义一个切如点 -->
<aop:pointcut expression="execution(* com.morhweb.dao.impl.*.*(..))" id="mypointcut"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="mypointcut"/>
</aop:config>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置DAO -->
<bean name="userDao" class="com.morhweb.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="user_annalDao" class="com.morhweb.dao.impl.UserAnnalDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="ticketDao" class="com.morhweb.dao.impl.TicketDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="ticketAnnal_annalDao" class="com.morhweb.dao.impl.TicketAnnalDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="orderFormDao" class="com.morhweb.dao.impl.OrderFormDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置service -->
<bean name="userService" class="com.morhweb.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean name="userAnnalService" class="com.morhweb.service.impl.UserAnnalServiceImpl">
<property name="userAnnalDao" ref="user_annalDao"></property>
</bean>
<bean name="ticketService" class="com.morhweb.service.impl.TicketServiceImpl">
<property name="ticketDao" ref="ticketDao"></property>
</bean>
<bean name="ticketAnnalService" class="com.morhweb.service.impl.TicketAnnalServiceImpl">
<property name="ticketAnnalDao" ref="ticketAnnal_annalDao"></property>
</bean>
<bean name="orderFormService" class="com.morhweb.service.impl.OrderFormServiceImpl">
<property name="orderFormDao" ref="orderFormDao"></property>
</bean>
<!-- 配置action -->
<bean name="userAction" class="com.morhweb.web.action.UserAction" scope="prototype">
<property name="userService" ref="userService"></property>
<property name="userAnnalService" ref="userAnnalService"></property>
</bean>
<bean name="orderFormAction" class="com.morhweb.web.action.OrderFormAction" scope="prototype">
<property name="orderFormService" ref="orderFormService"></property>
</bean>
<bean name="tickeAction" class="com.morhweb.web.action.TickeAction" scope="prototype">
<property name="orderFormService" ref="orderFormService"></property>
<property name="ticketService" ref="ticketService"></property>
<property name="ticketAnnalService" ref="ticketAnnalService"></property>
</bean>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。