SSH配置通用模板

 

 每天进步一点点,大家好,我是王亚豪,希望和每位程序猿爱好者共同学习,共同进步。我的QQ:369737397,欢迎和大家进行交流

applicationContext.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:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 启用注解扫描 -->
<context:annotation-config/>
<!-- 配置和一个testService对象 -->
<bean id="testServcie" class="com.hsp.test.TestServcie">
<property name="name" value="test"/>
</bean>

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
     <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orclhsp"/>
     <property name="username" value="scott"/>
     <property name="password" value="tiger"/>
      <!-- 连接池启动时的初始值 -->
  <property name="initialSize" value="30"/>
   <!-- 连接池的最大值 -->
   <property name="maxActive" value="500"/>
   <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
  <property name="maxIdle" value="2"/>
  <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
  <property name="minIdle" value="1"/>
</bean>
<!-- 配置会话工厂() -->
<bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     <!-- 设置数据源 -->
     <property name="dataSource" ref="dataSource"/>
     <!-- 接管了hibernate对象映射文件 -->
     <property name="mappingResources">
     <list>
       <value>com/hsp/domain/Employee.hbm.xml</value>
       <value>com/hsp/domain/Department.hbm.xml</value>
     </list>
     </property>
     <property name="hibernateProperties">
     <value>
          hibernate.dialect=org.hibernate.dialect.OracleDialect
          hibernate.hbm2ddl.auto=update
    hibernate.show_sql=true
    hibernate.cache.use_second_level_cache=true
             hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
             hibernate.generate_statistics=true      
  </value>
    </property>
</bean>

<!-- 配置EmployeeService对象 -->
<!-- 
<bean id="employeeService" class="com.hsp.service.imp.EmployeeService">
 <property name="sessionFactory" ref="sessionFactory" />
</bean>-->
<!-- 配置EmployeeService对象通过注解的方式来注入属性值,这是一个知识点 -->
<bean id="employeeService" class="com.hsp.service.imp.EmployeeService"/>
<bean id="departmentService" class="com.hsp.service.imp.DepartmentService">
 <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 配置action -->
<bean name="/login" scope="prototype" class="com.hsp.web.action.LoginAction"/>
<bean name="/employee" scope="prototype" class="com.hsp.web.action.EmployeeAction">
<property name="departmentService" ref="departmentService"/>
<property name="employeeService" ref="employeeService"/>
</bean>

<!-- 配置事务管理器,统一管理sessionFactory的事务 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 启用事务注解 -->
<tx:annotation-driven transaction-manager="txManager"/>

</beans>

 

 

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">
 
 
 <!-- 指定spring容器配置位置和名称 -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 
 <!-- 在服务器启动时创建Spring容器对象 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 

  <filter>
   <filter-name>strutsfilter</filter-name>
   <!-- 在struts2-core.jar包中 -->
   <filter-class>
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
   </filter-class>
  </filter>
 
  <filter-mapping>
   <filter-name>strutsfilter</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

 

 

 

 

 

 

 


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值