开发者社区> 问答> 正文

struts2 +srping3+hibernate4如何用配置文件进行开发不用注解形式

我这也在弄struts2 +srping3+hibernate4,但是我遇到问题不知道怎么配置,很多网上的例子都是annotation 形式的,看到你使用配置文件,希望你你能给我发一个demo

不胜感激

展开
收起
a123456678 2016-03-13 16:03:09 1839 0
1 条回答
写回答
取消 提交回答
  • <!-- 配置数据源 -->
     <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>
    2019-07-17 19:02:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring框架入门 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载