ssh整合之环境配置

在这里我将简述一下SSH整合的环境的配置

一、导入所有jar包

包含struts2,hiberna,spring的所有jar包,按所需可选导入dwr等扩展包

二、配置文件

在web.xml文件中写入如下代码:

<!--Struts2的Servlet-->
    <display-name>Struts Blank</display-name>

    <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>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext-*.xml
        </param-value>
    </context-param>
在src根目录,拷贝applicationContext-commons.xml、applicationContext-beans.xml、hibernate.cfg.xml、struts.xml四个最基本的配置文件

applicationContext-commons.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-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    <!--启用Aspectj对Annotation的支持-->

    <!--指定强制使用CGLIB来生成代理-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <!--Spring提供的Session生成方案-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation">
            <!--指定Hibernate配置文件的位置,classpath表示相对src目录位置-->
            <value>classpath:hibernate.cfg.xml</value>
        </property>
    </bean>

    <!--Spring提供的事务管理方案-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <!--事物需要Session,注入Session-->
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
    </bean>

    <!--AOP配置(切入点)-->
    <aop:config>
        <!--定义切入点,切入com.Hi_old.manager下所有类,所有方法-->
        <aop:pointcut id="allManagerMethod" expression="execution(* com.supermarket.services.*.*(..))"/>
        <!--指定事物的传播特性引用-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>
    <!--详细的传播特性配置-->
</beans>

applicationContext-beans.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-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
</beans>


hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -jdbc:oracle:thin:@192.168.3.98:1521:orcl-->
        <!--MySql驱动-->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <!--<property name="connection.url">jdbc:mysql://localhost/hibernate</property>-->
        <!--MySql数据库连接字符串-->
        <property name="connection.url">jdbc:mysql://zgamebbs.com/supermarket</property>
        <!--用户名-->
        <property name="connection.username">xxx</property>
        <!--密码-->
        <property name="connection.password">xxx</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">10</property>

        <!-- SQL dialect -->
        <!--指定Sql方言为MySql-->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <!--<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>-->

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <!--指定建表方案为更新-->
        <property name="hbm2ddl.auto">update</property>

    </session-factory>
</hibernate-configuration>

struts.xml:

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


三、各包名的创建

创建最基本的几个包:

domains(实体类与hibernate.hbm.xml文件目录)

actions(struts2的action处理类目录)

interfaces(持久层接口类目录)

services(持久层操作类目录)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值