SSH整合

3 篇文章 0 订阅
3 篇文章 0 订阅

struts-2.2.3.1  spring-framework-3.1.2  hibernate- 3.6.7整合。

可以看看Spring 连接池的配置 有JDBC、C3P0、BoneCP、Proxool。 http://blog.csdn.net/allen_gang/article/details/9067889

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">
  <welcome-file-list>
      <welcome-file> index.jsp</welcome-file>
   
  </welcome-file-list>
  
  
    <!-- 加载spring配置文件applicationContext.xml -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>    
  	<!-- 指明spring配置文件在何处 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:beans.xml</param-value>
    </context-param>
  
 
   <!-- struts2用到的核心过滤器配置 -->
   
 
   <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>
    </filter-mapping>  

  
</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:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.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">
           
	
	
 	<!-- 用注解方式注入bean  -->
	<!--
	<context:annotation-config />
	<context:component-scan base-package="com.peacemap" />
	-->
	
	<!-- 配置PropertyPlaceholderConfigurer方式的数据源 -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:jdbc.properties</value>
		</property>
	</bean>
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="${jdbc.driverClassName}" />
  <property name="url" value="${jdbc.url}" />
  <property name="username" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
 </bean> 
   <!--定义一个hibernate的SessionFactory-->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="annotatedClasses">
			<list>
				<value>com.tech.allen.model.User</value>
				 
			</list>
		</property>
		
		
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.Oracle10gDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
	</bean>
	
	<!-- 注入HibernateTemplate -->
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<!--
	<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	-->
	
	
	
	
	
	<!--   业务逻辑组件 -->  
	
	<!-- 用户管理 -->
	<bean name="UserDao" class="com.tech.allen.dao.impl.UserDaoImpl">
		<property name="hibernateTemplate" ref="hibernateTemplate">
		</property>
	</bean>
	<bean name="UserService" class="com.tech.allen.service.impl.UserServiceImpl">
		<property name="UserDao" ref="UserDao"/>
		 
	</bean>
	
	<bean name="UserAction" class="com.tech.allen.action.UserAction">
		<property name="UserService" ref="UserService"/>
		 
	</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="org.apache.struts2.spring.StrutsSpringObjectFactory" />
		<!--
	<constant name="struts.objectFactory.spring.autoWire" value="type"/>	
	<constant name="struts.objectFactory" value="spring"/>	
    <constant name="struts.devMode" value="false" />

   -->
   
   <package name="json" extends="struts-default">
   
 
      
      <!-- UserAction  -->
       <!--    用户            -->
 
        <action name="getUserList" class="UserAction" method="getUserList">
           <result name="success" >success.jsp</result>
          
        </action>
        
 
       </package>
     
 

</struts>

所需要jar文件 http://download.csdn.net/detail/allen_gang/5560593

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值