SSH框架学习笔记(1)

SSH框架学习笔记(1)


在ssh框架常用到的配置文件有applicationContext.xml、struts.xml、db.properties等,下面展示几种常见的配置:

applicationContext.xml配置内容:


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    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.2.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    
    <context:property-placeholder location="classpath:db.properties" />

    

    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="jdbcUrl" value="${jdbcUrl}">property>
        <property name="driverClass" value="${driverClass}">property>
        <property name="user" value="${user}">property>
        <property name="password" value="${password}">property>
        
        <property name="initialPoolSize" value="3">property>
        
        <property name="minPoolSize" value="3">property>
        
        <property name="maxPoolSize" value="3">property>
        
        <property name="acquireIncrement" value="3">property>
        
        <property name="maxIdleTime" value="1800">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.MySQL5Dialectprop>
                <prop key="hibernate.show_sql">trueprop>
                <prop key="hibernate.hbm2ddl.auto">updateprop>
                <prop key="javax.persistence.validation.mode">noneprop>
                <prop key="hibernate.autoReconnect">trueprop>
            props>
        property>
        <property name="mappingResources">
            <list>
                <value>bean/User.hbm.xmlvalue>
                <value>bean/Privileges.hbm.xmlvalue>
            list>
        property>
    bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    bean>
    <tx:annotation-driven transaction-manager="transactionManager" />
    <bean id="PrivilegesDAO" class="dao.PrivilegesDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        property>
    bean>
    
    <bean id="userDAO" class="dao.UserDAOImpl">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        property>
    bean>
    <bean id="userService" class="service.impl.UserServiceImpl">
        <property name="userDAO">
            <ref bean="userDAO" />
        property>
    bean>
    <bean id="login" class="action.LoginAction">
        <property name="userService">
            <ref bean="userService" />
        property>
    bean>

    
    <bean id="txMananger"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory">property>
    bean>

    
    <tx:advice id="txAdvice" transaction-manager="txMananger">
        <tx:attributes>
            <tx:method name="get*" read-only="true" />
            <tx:method name="find*" read-only="true" />
            <tx:method name="list*" read-only="true" />
            <tx:method name="*" rollback-for="Throwable" />
        tx:attributes>
    tx:advice>

    
    <aop:config>
        <aop:pointcut expression="execution( * service.impl.*.*(..))"
            id="serviceOperation" />
        
        
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
    aop:config>

beans>

struts.xml配置内容:



<struts>
    <package name="default" extends="struts-default">
        <action name="Log" class="action.LoginAction" >
            <result name="success">index.jspresult>
            <result name="error">login.jspresult>
        action>
    package>
struts>    

db.properties配置内容:

jdbcUrl=jdbc\:mysql\://localhost\:3306/yourdbname
driverClass=com.mysql.jdbc.Driver
user=root
password=123456

小结:在整合spring+struts2+hibernate框架时,经常会遇到框架之间的jar包版本冲突,这个主要是由于版本更进会导致一些方法被遗弃或者修改。

原创文章,转载需注明出处http://blog.csdn.net/drohe/article/details/73755952

你可能感兴趣的:(j2ee)