星空网 > 软件开发 > ASP.net

如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...

前言:

本文适合部署SSH项目失败的,主要解决部署时的异常!

我为什么要写这篇文章?

  学了一个周的Spring了,部署个SSH项目都到处报错,为一个sessionFactoty can't be build异常困扰了一个周,根本冷静不下来,难道跟 Spring 这么无缘?NO NO NO,不完全是这样的!

  最近冷静下来,重新部署了一次项目,成功了!下面与同样被sessionFactory 或者说applicationContext.

正文:

  整合SSH总体的步骤:

    加入架包-->编写web.

-->编写struts.

    

  1、架包

    如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...

  下载地址:SSH整合所需架包 / SSH整合所需架包(二) 总大小:14MB  

  2、web.

如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...
 1 <??> 2 <web-app version="3.0"  3   ="http://java.sun.com/  4   ="http://www.w3.org/2001/  5   xsi:schemaLocation="http://java.sun.com/ 6   http://java.sun.com/> 7  <!--告诉默认读取哪个配置-->  8  <context-param> 9    <param-name>contextConfigLocation</param-name>10    <param-value>classpath:applicationContext.</param-value>11  </context-param>12  <!--开启监听:不开启将无法读取context-paramm-->13  <listener>14    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>15    16  </listener>17  <!--开启事务过滤器-->18  <filter>19    <filter-name>OpenSessionInViewFilter</filter-name>20    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>21  </filter>22  <filter-mapping>23    <filter-name>OpenSessionInViewFilter</filter-name>24    <url-pattern>*.action</url-pattern>25  </filter-mapping>26  <!--struts2配置-->27  <filter>28    <filter-name>struts2</filter-name>29    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>30  </filter>31  32  <filter-mapping>33    <filter-name>struts2</filter-name>34    <url-pattern>/*</url-pattern>35  </filter-mapping>36 </web-app>

web.

 

  3、hibernate.cfg.

如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...
 1 <!DOCTYPE hibernate-configuration PUBLIC 2   "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 3   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 4  5 <hibernate-configuration > 6   <session-factory > 7    8   <!-- hibernate.dialect(方言)使用的是哪一种数据库  9   org.hibernate.dialect.MySQLDialect10   org.hibernate.dialect.SQLServerDialect11   -->12   <property name="hibernate.dialect">13   org.hibernate.dialect.MySQLDialect14   </property>15   16   <!-- 数据库驱动类 17   com.mysql.jdbc.Driver18   com.microsoft.sqlserver.jdbc.SQLServerDriver19   -->20   <property name="hibernate.connection.driver_class">21   com.mysql.jdbc.Driver22   </property>23   24   <!-- 用户名 -->25   <property name="connection.username">root</property>26   27   <!-- 用户密码 -->28   <property name="connection.password">abc123</property>29   30   <!-- 自动建表 -->31   <property name="hibernate.hbm2ddl.auto">update</property>32   33   <!-- url 34   jdbc:sqlserver://localhost:1344;DataBaseName=testDB35   -->36   <property name="connection.url">jdbc:mysql://localhost:3306/use4class</property>37   38   <!-- 控制台查看sql语句 -->39   <property name="show_sql">true</property>40   41   <!-- 控制台查看格式化sql语句 -->42   <property name="hibernate.format_sql">true</property>43   44   <!-- 告诉hibernate映射文件路径 -->45   46 47   </session-factory>48  49 </hibernate-configuration>

hibernate.cfg.

  我使用的mysql数据库,如果你使用别的数据库,请替换家暴、修改驱动、登录信息、数据库语言

  4、struts.

如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...
 1 <??> 2 <!DOCTYPE struts PUBLIC 3   "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" 4   "http://struts.apache.org/dtds/struts-2.1.dtd"> 5  6 <struts> 7   <!-- 允许使用动态方法 --> 8   <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> 9   <!-- 字符编码 -->10   <constant name="struts.i18n.encoding" value="utf-8"></constant>11   <!-- 主题 -->12   <constant name="struts.ui.theme" value="simple"></constant>13   <!-- 开发者模式 -->14   <constant name="struts.devMode" value="true"></constant>15   <!-- 国际化 -->16   <constant name="struts.custom.i18n.resources" value="message"/>17   <package name="default" namespace="/" extends="struts-default">18     <!-- 获取文章 -->19     <!--<action name="*Sys" method="{1}">20       <result name="success" >/index.jsp</result>21       <result name="input">/login.html</result>22       <result name="suc">index.jsp</result>23       <result name="err">login.html</result>24     </action>-->25     26   </package>27 </struts>

struts.

  5、applicationContext.

如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...
 1 <??> 2 <beans ="http://www.springframework.org/schema/beans" 3     ="http://www.w3.org/2001/ 4     ="http://www.springframework.org/schema/p" 5     ="http://www.springframework.org/schema/context" 6     ="http://www.springframework.org/schema/tx" 7     ="http://www.springframework.org/schema/aop" 8     xsi:schemaLocation=" 9       http://www.springframework.org/schema/aop 10       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd11      http://www.springframework.org/schema/beans12      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd13      http://www.springframework.org/schema/context14      http://www.springframework.org/schema/context/spring-context-3.0.xsd15       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">16 17     18 19 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">20   <property name="configLocation">21     <value>classpath:hibernate.cfg.</value>22   </property>23   <property name="mappingDirectoryLocations">24     <list>25       <value>classpath:com/jboa/entity/</value>26     </list>27   </property>28 </bean>29 30 31 <!-- 配置hibernate -->32 <bean id="hibernateTeamp" class="org.springframework.orm.hibernate3.HibernateTemplate">33   <constructor-arg name="sessionFactory" ref="sessionFactory"></constructor-arg>34 </bean>35 36 37 <!-- Dao配置 -->38 <bean id="empDao" class="com.jboaoffice.impl.SysEmployeeImpl">39   <property name="hibernateTemplate" ref="hibernateTeamp"></property>40 </bean>41 42 <!-- biz配置 -->43 <bean id="empBiz" class="com.jboaoffice.biz.impl.SysEmployeeBizImpl">44   <property name="empdao" ref="empDao"></property>45 </bean>46 47 <!-- action 配置 -->48 <bean id="empAction" class="com.jboaoffice.action.SysAction">49   <property name="empBiz" ref="empBiz"></property>50 </bean>51 52 53 <!-- 配置事务管理器 -->54 <!-- <bean id="txManager" >55    <property name="sessionFactory" ref="sessionFactory"></property>56  </bean>57  <tx:advice id="txadvice" transaction-manager="txManager">58    <tx:attributes>59      <tx:method name="get*" read-only="true"/>60      <tx:method name="find*" read-only="true"/>61      <tx:method name="search*" read-only="true"/>62      <tx:method name="list*" read-only="true"/>63      <tx:method name="update*" propagation="REQUIRED"/>64      <tx:method name="del*" propagation="REQUIRED"/>65      <tx:method name="save*" propagation="REQUIRED"/>66    </tx:attributes>67 68  </tx:advice>69  aop config70 <aop:config>71   <aop:pointcut expression="execution(* com.jboaoffice.bi.impl.*.*(..))" id="tx"/>72   <aop:advisor advice-ref="txadvice" pointcut-ref="tx" />73 </aop:config>74  -->75 </beans>

applicationContext.

  请注释掉sessionFactory后面</bean>前面的代码【那是配置dao、hibernateTemplate、biz、action自动注入的】,做完这几个工作你就可以运行服务!

  applicationContext里面的配置有很多种形式,先把基础的做了

  6、完善代码

    1、下面你可以去完善entityBean & entityBean.hbm.

    2、dao、 biz(service)、action 代码 并且去配置struts   

    3、请取消注释sessionFactory后面</bean>前面的代码

    再运行应该不会报框架的问题了!

 小总结:

  根据以往在web中使用框架的经验:

    1、架包正确(缺架包一般都会报出 classnotfound 的异常,后面就是一长串命名空间 :很好找)

    2、配置正确 (spring 框架我遇到最多的是sessionFactory can't be build )

    3、配置中提到的 java bean 存在 (java bean 不存在 提示很明显的 直接把你配置里面的bean id 打印出来,对症下药方可解决)

    即可正常启动服务!

  我经常犯得错误:

    1、【配置】少配置内容、命名错误、bean 关系不完整

    2、【Java代码】反向工程建映射文件【Spring可能会不买账】,我的是出问题了,报sessionFactory can't be build 的异常

    sessionFactory can't be build :

    这是个困扰我很久的异常,这个异常详细内容有这么一段话

    如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...

 如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...   

google 过后得到的答案是使用了低版本hibernate 、高版本的springFramework  ,

我崩溃了,于是我就重新建项目,按照这个流程,成功了。上面那个问题我会再检查,看到的朋友,如果你遇到过并且解决了,请告诉我;或者你知道这是什么原因,告诉我,告诉大家!

 

  

 

 

☞出自新手之笔,如有错误,请提出,大家一起纠正☜

 

    

  




原标题:如何部署一个简单的SSH框架?只需要这几个步骤,请戳开...

关键词:SSH

SSH
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流