ssh整合

ssh整合

环境

  1. struts2+spring4+hibernate4
  2. jdk1.7
  3. myeclipse

一、导包

1.struts2中的包

struts-2.3.30\apps\struts2-blank\WEB-INF的lib中的全部;
struts-2.3.30\lib中的:
aopalliance-1.0.jar
struts2-spring-plugin-2.3.30.jar

2.spring中的包

spring-framework-4.3.5.RELEASE-dist\spring-framework-4.3.5.RELEASE\libs中的全部(并不是全部都必须)

3.hibernate中的包

\hibernate-release-4.3.11.Final\lib中
required下的全部;
jpa下的全部;
optional\c3p0下的全部;

4.loging包

commons-logging-1.1.1.jar

5.mysql连接器

mysql-connector-java-5.1.7-bin.jar

6.json转换工具

fastjson-1.2.9.jar

7.aop相关包

aspectjweaver.jar
aopalliance-1.0.jar

二、配置xml

1 .web.xml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>sshDemo1display-name>
    <welcome-file-list>
        <welcome-file>index.jspwelcome-file>
    welcome-file-list>
    
    <filter>
        <filter-name>strutsfilter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterfilter-class>

    filter>
    <filter-mapping>
        <filter-name>strutsfilter-name>
        <url-pattern>*.actionurl-pattern>
    filter-mapping>
    
    
    <context-param>
        
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:applicationContext.xmlparam-value>
    context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>
web-app>

2.struts.xml

在src根目录新建一个struts.xml

文档约束来自web app libraries下的struts2-core-2.3.30.jar/struts-2.3.dtd文件中


 

<struts>
    <constant name="struts.devMode" value="true">constant>
    <package name="my" namespace="/" extends="struts-default">
    
        <action name="user_*" class="userAction" method="{1}">
            <result name="ok">/ok.jspresult>
        action>
    package>
struts>

3.applicationContext.xml

文档约束可以从spring包的文档中查找;添加后保存重新打开,xml的NameSpaces视图中可以选择其他约束;


<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" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd 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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    
    <context:component-scan base-package="com">context:component-scan>

    
    <context:property-placeholder location="classpath:jdbc.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="${username}">property>
        <property name="password" value="${password}">property>
        
        
        <property name="initialPoolSize" value="3">property>
        
        <property name="minPoolSize" value="3">property>
        
        <property name="maxPoolSize" value="5">property>
        
        <property name="acquireIncrement" value="3">property>
        
        <property name="maxStatements" value="8">property>
        
        <property name="maxStatementsPerConnection" value="5">property>
        
        <property name="maxIdleTime" value="1800">property>
    bean>

    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">property>
        
        <property name="configLocation" value="classpath:hibernate.cfg.xml">property>

        
    
        <property name="hibernateProperties">
            <props>
                <prop key="">prop>
            props>
        property>

    bean>


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

    
    <aop:aspectj-autoproxy proxy-target-class="true">aop:aspectj-autoproxy>
    <tx:annotation-driven transaction-manager="transactionManager" />

beans>

4.jdbc.properties数据库信息配置文件

jdbcUrl=jdbc:mysql://localhost:3306/c19
driverClass=com.mysql.jdbc.Driver
username=root
password=root

5.hibernate.cfg.xml

若使用applicationContext.xml来配置sessionFactory信息则可以省略此配置文件.




<hibernate-configuration>
<session-factory>
    <property name="dialect">
        org.hibernate.dialect.MySQLDialect
    property>
    <property name="hbm2ddl.auto">updateproperty>
    <property name="show_sql">trueproperty>
    <mapping resource="com/xingxue/model/User.hbm.xml" />

session-factory>
hibernate-configuration>

你可能感兴趣的:(ssh整合)