手动搭建SSH框架

在MyEclipse中新建个WEB项目。

添加struts2.1支持:

       jar包:freemarker.jar,ognl.jar,struts2-core.jar,struts2-spring-plugin.jar,xwork-core.jar,commons-fileupload.jar。

      添加hibernate3.3.2支持:

       jar包:hibernate3.jar,antlr.jar,commons-collections.jar,dom4j.jar,javassist.jar,jta.jar,c3p0.jar,slf4j-api.jar,slf4j-nop.jar(另外下)。

      annotation支持的jar包:hibernate-annotations.jar,ejb3-persistence.jar,hibernate-commons-annotations.jar。

添加spring2.5支持:

       jar包:spring.jar。

在scr目录下添加struts.xml文件,其内容:

           <?xml version="1.0" encoding="GBK" ?>

           <!-- 指定Struts 2配置文件的DTD信息 -->

           <!DOCTYPE struts PUBLIC

            "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"

            "http://struts.apache.org/dtds/struts-2.1.dtd">

            <struts>

            </struts>

在web.xml文件中添加struts2过滤器与spring容器,其xml内容:

            <?xml version="1.0" encoding="GBK"?>

            <!-- 配置Web应用配置文件的根元素,并指定配置文件的Schema信息 -->

            <web-app 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" version="2.5">

            <!-- 配置加载Spring容器 -->

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

            <!-- 定义Struts 2的核心控制器:FilterDispatcher -->

            <filter>

                <filter-name>struts2</filter-name>

                <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

            </filter>

            <filter-mapping>

                 <filter-name>struts2</filter-name>

                 <url-pattern>/*</url-pattern>

            </filter-mapping>

与web.xml文件同目录添加applicationContext.xml文件,其内容:

<?xml version="1.0" encoding="GBK"?>

<!-- 指定Spring配置文件的Schema信息 -->

      <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.5.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 id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  destroy-method="close">
             <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
             <property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;DatabaseName=mytest"/>
              <property name="user" value="sa"/>
              <property name="password" value="123456"/>
          </bean>

<bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
              <property name="dataSource" ref="dataSource"/>
              <property name="hibernateProperties">
                 <props>
                      <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                        <prop key="hibernate.hbm2ddl.auto">update</prop>
                       <prop key="hibernate.show_sql">true</prop>
                       <prop key="hibernate.format_sql">true</prop>
                   </props>
                </property>
              </bean>

</beans>

这样就大概完成了基础的框架了。我连的是SQL 2005,所以还要加SQL的JDBC包。

你可能感兴趣的:(spring,框架,Hibernate,struts,ssh)