SSH框架的搭建

这是比较重要的:

+++++++++++++spring整合hibernate:

首先,将会话工厂整合了

其次将食物的开启和关闭也整合了。

为什么要在业务层中加入事务:因为在实际的项目中,业务是相对来说比较复杂的,有时候要访问很多次数据库,很有可能是访问不同的数据库,会对数据的完整性造成影响,这是时候就需要使用事务。

声明式事务的核心问题是:对哪些方法,采取什么样的事务策略。

配置步骤:

  导入tx,和aop命名空间

  配置事务管理器,并且为其注入sessionFactory,

  基于该事务管理器配置事务增强,指定事务规则

  配置切面,    定义切入点,织入事务切面

在使用oracle数据库的时候应该注意的问题:

注意:这两个序列的名字应该是一样的。

注意:是在添加不进去数据的时候,偷懒的办法,将数据库中的表中的字段设置为nullable,就能够添加进去数据了,同样主键也能够自动生成出来。

 +++++++++++++++spring与struts2的继承+++++++++++++++++++++

 注意:这里的action的实例还是有struts2创建的,业务bean如何注入给action,是通过spring容器注入的。

在web.xml文件中监听器是最先被执行的。这个jar文件很重要。

这是web.xml文件中需要配置的东西:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<display-name></display-name>
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--指定spring的配置文件 -->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 配置监听器 启动spring 容器 -->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置延迟加载 这里可以不用配置,但是一般情况下是建议配置上的-->
<filter>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

</filter>
<filter-mapping>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <url-pattern>*.action</url-pattern>
</filter-mapping>

<!--配置struts2本身就需要的过滤器 -->
<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><!--表示所有的请求都由struts框架来进行处理 -->
</filter-mapping>

</web-app>

注意:由于自己的粗心,一定要注意用户和密码,一定要输入正确。

struts2和spring集成的第二种方式

 这种方式一般情况下不怎么用,因为会增加复杂度.

注意:第一种方式和第二种方式是能够同时存在的

spring  中bean的作用域

*使用注解实现ssh的集成

  目的:解决在spring配置文件中的代码量

原文地址:https://www.cnblogs.com/dongyaotou/p/9911026.html