使用Java企业级技术开发大型系统(3)

没有(2)

 

web.xml:


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

applicationContext.xml:
<!-- 全局采用注解配置 -->
<context:annotation-config></context:annotation-config>
<!-- 注解扫描范围 -->
<context:component-scan base-package="com.xx"></context:component-scan>
<!-- 配置事务通知 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"> </property>
</bean>
<!-- 声明式事物采取注解植入 -->
<tx:annotation-driven transaction-manager="txManager"/>

struts.xml:
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="findAll" class="customerAction" method="findAll">
<result name="success">index.jsp</result>
</action>

<action name="findPage" class="customerAction" method="findByPage">
<result name="success">page.jsp</result>
</action>
</package>
</struts>

创建事务通知 通知以XXX方法打头 需要怎样的事务处理
以save开头的方法 需要事务处理
以find开头的方法 只读即可 (不需要事务)

Spring框架支持 通过MyEclipse导入
需要加入5个jar包

Hibernate框架支持 通过MyEclipse导入
注意:删除cglib-2.2.jar

Struts2框架支持 手动引入Struts2jar包
提示:
从struts-2.1.8.1-all.zip压缩包中找apps目录下的
struts2-blank-2.1.8.1.war文件直接打开,从这个项
目中可以找到相关的jar包,包括struts.xml和web.xml都
可以从这个项目中找到。
注意: 多加入一个 struts2-spring-plugin-2.1.8.1.jar

调整各个配置文件
applicationContext.xml 修改警告
struts.xml 修改警告
web.xml 配置监听(Listener)
org.springframework.web-3.0.1.RELEASE-A.jar 包中找 : org.springframework.web.context.ContextLoaderListener

使用Hibernate反向生成实体映射
检查自动生成的映射文件和实体类

编写DAO 在spring中注册
注意:不在使用HibernateUtil,而采用继承HibernateDaoSupport的方式

编写BIZ 在spring中注册

编写Action 在spring中注册
注意:
scope="prototype"
struts.xml 配置文件中 class不是配置类路径了,而是配置spring中的bean id

Hibernate加载策略
延迟加载 session.load() 代理对象,当使用这个对象的属性时才去加载
load查询的对象不存在时抛出异常
立即加载 session.get() 立即发送SQL语句到数据库并填充对象
get查询的对象不存在时候返回null

使用内部类这种写法比较靠谱,但是需要注意如果使用外部类成员,需要使用final修饰

posted on 2017-03-31 00:56  凌雨轩林  阅读(141)  评论(0编辑  收藏  举报

导航