Struts2+Hibernate+Spring配置

 

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/bean.xml</param-value>
 </context-param>
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
   <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern> 
    </web-app>

bean.xml——

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"


 xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"></property>
<property name="url" value="jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=heros"></property>
<property name="username" value="sa"></property>
<property name="password" value="123456"></property>

</bean>

 <bean id="sessionFactory" 
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">          <property name="dataSource">  
           <ref bean="dataSource" />  
       </property>   
           <property name="hibernateProperties"> 
       <value>hibernate.dialect=org.hibernate.dialect.SQLServerDialect
       hibernate.hbm2ddl.auto=update
       hibernate.show_sql=true
         </value> 
             </property>  
     <property name="mappingResources">  
           <list>  
               <value>com/SSH/Manager.hbm.xml</value>  
               <value>com/SSH/Job.hbm.xml</value>
                 
                           </list>  
       </property>  
   </bean>
     <context:annotation-config></context:annotation-config>
        <bean id="txManager"
 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory">
 
  </property>
 </bean>
  <tx:annotation-driven transaction-manager="txManager"/>

<bean id="people" class="com.SSH3.UsersBean"/>
<bean id="pers" class="com.SSH4.UpdateAction" scope="prototype">

</bean>

</beans>

Struts.xml——

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

<struts>
<constant name="struts.objectFactory" value="spring"></constant>
<package name="struts2" extends="struts-default">
<action name="Lgcin" class="pers">
<result name="success">/Wel.jsp</result>
<result name="input">/Login.jsp</result>
</action>
 </package>

 </struts>

hibernate的配置

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.spring" >

    <class name="com.SSH.Job" table="Job">
        <id name="id">
      <generator class="native"></generator>
        </id>
        <property name="copname" />
           </class>

   </hibernate-mapping>

 

   


 

 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值