ssh整合的配置

来源:互联网 发布:金冠网络创业平台 编辑:程序博客网 时间:2024/04/27 02:37

配置问题

       1):web.xml中配置

              1<context-param>

                     <param-name>contextConfigLocation</param-name>

                     <param-value>WEB-INF/spring.xml</param-value>                                        </context-param>告诉web容器, spring配置文件的地址

              2<listener>

                   <listener-class>

                            org.springframework.web.context.ContextLoaderListener

                     </listener-class>

              </listener>web容器启动的时候加载spring配置文件

       2)struts1中配置

              1<controller  processorClass=

                     "org.springframework.web.struts.DelegatingRequestProcessor"/>

       3)spring中配置

              1管理数据源

              <bean id="dataSource"

              class="org.apache.commons.dbcp.BasicDataSource">

              <property name="driverClassName"

                     value="com.mysql.jdbc.Driver">

              </property>

              <property name="url" value="jdbc:mysql://localhost:3306/my"/>

                     <property name="username" value="root"/>

                     <property name="password" value="root"/>

              </bean>

              2管理sessionFactory

              <bean

                     id="sessionFactory"          class=

                     "org.springframework.orm.hibernate3.LocalSessionFactoryBean">

                     <property name="dataSource">

                            <ref bean="dataSource"></ref>

                     </property>

                     <property name="hibernateProperties">

                            <props>

                                   <prop key="hibernate.dialect">

                                          org.hibernate.dialect.MySQLDialect

                                   </prop>

                            </props>

                     </property>//第个实体类对应的下面的xml配置文件

                     <property name="mappingResources">

                     <list>

                            <value>com/hf/po/Login.hbm.xml</value>

                     </list>

                     </property>

              </bean>

              3切面

                     <!-- 切面 -->

              <bean id="tsm" class=

                     "org.springframework.orm.hibernate3.HibernateTransactionManager">

                     <property name="sessionFactory" ref="sessionFactory"></property>

              </bean>

              4事务传播行为

              <bean id="loginBiz" class=

         "org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

                     <property name="transactionManager" ref="tsm"/>

                     <property name="target" ref="loginBiaTarget"/>

                     <property name="transactionAttributes">

                            <!-- 事务传播行为 -->

                            <props>

                                   <!-- 默认情况下,只有当方法抛出异常

                                          RuntimeException或其子类时,回滚事务 -->

                                   <prop key="find*">

                                          PROPAGATION_REQUIRED,readOnly

                                   </prop><!-- 只读事务 -->

                                   <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>

                                   <prop key="*">PROPAGATION_REQUIRED</prop>

                            </props>

                     </property>

              </bean>

              5实体类entity

       <hibernate-mapping>

          <class name="com.hf.po.Login" table="login" catalog="my">

               <id name="uid" type="java.lang.Integer">

                  <column name="uid" />

                <generator class="native"></generator>

             </id>

             <property name="username" type="java.lang.String">

                <column name="username" length="20" />

             </property>

             <property name="userpswd" type="java.lang.String">

                <column name="userpswd" length="20" />

             </property>

          </class>

       </hibernate-mapping>

原创粉丝点击