@赵世传 你好,想跟你请教个问题:兄弟 我这也在弄struts2 +srping3+hibernate4,但是我遇到问题不知道怎么配置,很多网上的例子都是annotation 形式的,看到你使用配置文件,希望你你能给我发一个demo
不胜感激
十分感谢,我自解决了。要两种形式都会,我一直没有成功后来发现换struts2包后可以了.很奇怪
很简单,不过还是推荐注解方式
<!-- 配置数据源 --> <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>
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
十分感谢,我自解决了。要两种形式都会,我一直没有成功后来发现换struts2包后可以了.很奇怪
很简单,不过还是推荐注解方式
<!-- 配置数据源 -->
<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>