hibernate(applicationContext.xml)

来源:互联网 发布:小球发射java源代码 编辑:程序博客网 时间:2024/05/17 21:59

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
  </property>
  <property name="url"
   value="jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs;selectMethod=cursor">
  </property>
  <property name="username" value="sa"></property>
 </bean>

 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>
   </props>
  </property>
  <property name="mappingResources">
   <list>
    <value>hibernate/Users.hbm.xml</value>
   </list>
  </property>
 </bean>
 <bean id="userDao" class="dao.impl.HibernateUsersDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 
  事务装备,做真正的事务处理
 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 

 <bean id="realFacade" class="facade.Facade">
  <property name="userDao" ref="userDao"></property>
 </bean>
 <!-- 配置抽象的aop-->
 <bean id="abstractProxy" abstract="true"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionAttributes">
   <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="login*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 <!-- 配置具体的代理-->
 <bean id="facade" parent="abstractProxy">
  <property name="target" ref="realFacade"></property>
 </bean>
 <bean name="/login" class="struts.action.LoginAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/update" class="struts.action.UpdateAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/delete" class="struts.action.DeleteAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/insert" class="struts.action.InsertAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/getByUserName"
  class="struts.action.GetByUserNameAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/getAll" class="struts.action.GetAllAction">
  <property name="facade" ref="facade"></property>
 </bean>
 <bean name="/getPage" class="struts.action.GetPageAction">
  <property name="facade" ref="facade"></property>
 </bean>
</beans>

 

 

在struts-config.xml中的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
  <form-beans >
    <form-bean name="usersForm" type="struts.form.UsersForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards >
    <forward name="success" path="/success.jsp" />
    <forward name="error" path="/error.jsp" />

  </global-forwards>

  <action-mappings >
    <action
      attribute="usersForm"
      name="usersForm"
      path="/insert"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" />
    <action
      attribute="usersForm"
      name="usersForm"
      path="/update"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" />
      <action
      attribute="usersForm"
      name="usersForm"
      path="/delete"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" />
      <action
      attribute="usersForm"
      name="usersForm"
      path="/getByUserName"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" >
      <forward name="success" path="/update.jsp" />
      </action>

      <action
      path="/login"
      type="org.springframework.web.struts.DelegatingActionProxy" >
      <forward name="success" path="/index.jsp" />
      </action>

 <action
      path="/getAll"
      type="org.springframework.web.struts.DelegatingActionProxy" >
      <forward name="success" path="/getPage.do" />
 </action>
 <action
      path="/getPage"
      type="org.springframework.web.struts.DelegatingActionProxy" >
      <forward name="success" path="/userList.jsp" />
 </action>

  </action-mappings>

  <message-resources parameter="struts.ApplicationResources" />
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
</struts-config>

 

 

 

 

原创粉丝点击