﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Programming on the fly-随笔分类-22.Spring</title><link>http://www.blogjava.net/Werther/category/39067.html</link><description>Live as if you were to die tomorrow. Learn as if you were to live forever.
</description><language>zh-cn</language><lastBuildDate>Thu, 02 Jul 2009 13:18:33 GMT</lastBuildDate><pubDate>Thu, 02 Jul 2009 13:18:33 GMT</pubDate><ttl>60</ttl><item><title>Spring工作原理探秘 </title><link>http://www.blogjava.net/Werther/archive/2009/07/02/285219.html</link><dc:creator>Werther</dc:creator><author>Werther</author><pubDate>Thu, 02 Jul 2009 09:34:00 GMT</pubDate><guid>http://www.blogjava.net/Werther/archive/2009/07/02/285219.html</guid><wfw:comment>http://www.blogjava.net/Werther/comments/285219.html</wfw:comment><comments>http://www.blogjava.net/Werther/archive/2009/07/02/285219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Werther/comments/commentRss/285219.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Werther/services/trackbacks/285219.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 　Spring的哲学是在不影响Java对象的设计的情况下将Java对象加入到框架中。 我们下面来看看Spring的工作原理，看看Spring是如何做到不影响Java对象的。 &nbsp;&nbsp;<a href='http://www.blogjava.net/Werther/archive/2009/07/02/285219.html'>阅读全文</a><img src ="http://www.blogjava.net/Werther/aggbug/285219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Werther/" target="_blank">Werther</a> 2009-07-02 17:34 <a href="http://www.blogjava.net/Werther/archive/2009/07/02/285219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring 框架简介(轉載)</title><link>http://www.blogjava.net/Werther/archive/2009/06/30/284799.html</link><dc:creator>Werther</dc:creator><author>Werther</author><pubDate>Tue, 30 Jun 2009 09:22:00 GMT</pubDate><guid>http://www.blogjava.net/Werther/archive/2009/06/30/284799.html</guid><wfw:comment>http://www.blogjava.net/Werther/comments/284799.html</wfw:comment><comments>http://www.blogjava.net/Werther/archive/2009/06/30/284799.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Werther/comments/commentRss/284799.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Werther/services/trackbacks/284799.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Spring 框架是一个分层架构，由 7 个定义良好的模块组成。Spring 模块构建在核心容器之上，核心容器定义了创建、配置和管理 bean 的方式.&nbsp;&nbsp;<a href='http://www.blogjava.net/Werther/archive/2009/06/30/284799.html'>阅读全文</a><img src ="http://www.blogjava.net/Werther/aggbug/284799.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Werther/" target="_blank">Werther</a> 2009-06-30 17:22 <a href="http://www.blogjava.net/Werther/archive/2009/06/30/284799.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring总结</title><link>http://www.blogjava.net/Werther/archive/2009/06/29/284637.html</link><dc:creator>Werther</dc:creator><author>Werther</author><pubDate>Mon, 29 Jun 2009 09:22:00 GMT</pubDate><guid>http://www.blogjava.net/Werther/archive/2009/06/29/284637.html</guid><wfw:comment>http://www.blogjava.net/Werther/comments/284637.html</wfw:comment><comments>http://www.blogjava.net/Werther/archive/2009/06/29/284637.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Werther/comments/commentRss/284637.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Werther/services/trackbacks/284637.html</trackback:ping><description><![CDATA[一、事务管理 <br />
事务传播 <br />
1、required:方法在一个事务中执行，如果调用的方法在一个事务中，则使用该事务，否则将创建一个新的事务。(必须有，有就用，没有就建) <br />
2、mandatory:如果运行于事务中的客户调用了该方法，方法在客户的事务中执行。如果客户没有关联到事务中，容器就会抛出TransactionRequiredException.(必须有，有就用，没有报错) <br />
3、requiresnew:方法将在一个新的事务中执行，如果调用的方法已经在一个事务中，则暂停旧的事务。在调用结束后恢复旧的事务。(必须有，有没有都要建) <br />
4、supports:如果方法在一个事务中被调用，则使用该事务，否则不使用事务。(有没有都中，有就用，没有不用) <br />
5、not_supported:如果方法在一个事务中被调用，容器会在调用之前终止该事务。在调用结束后，容器会恢复客户事务。如果客户没有关联到一个事务中，容器不会入运行在该方法启动一个新的事务。用notsupported属性标识不需要事务的方法。因为事务会带来更高的性能支出，所以这个属性可以提高性能。(不需要，有就挂起事务，没有直接运行) <br />
6、Never:如果在一个事务中调用该方法，容器会抛出RemoteException。如果客户没有关联到一个事务中，容器不会在运行入该方法前启动一个新的事务。(必须没有，有就报错，没有就直接运行) <br />
事务隔离 <br />
为什么要使用事物隔离，是因为事物并发引起的一些错误现象 <br />
并发问题： <br />
脏读：一个事务读取了未提交的事务 <br />
不可重复读：同一个事务中多次读取同一个数据返回的结果不同 <br />
幻读：一个事务读取到了另一个事务已提交的insert数据。 <br />
<br />
事务并发处理： <br />
共享锁：共享锁用于读取数据操作，它允许其他事务同时读取某锁定的资源，但不允许其他事务更新它。 <br />
排他锁：排它锁用于修改数据的场合。它锁定的资源，其他事务不能读取也不能修改。 <br />
更新锁：更新锁在更新操作的初始化阶段用来锁定可能要被修改的资源，从而避免使用共享锁造成的死锁现象。 <br />
<br />
事务隔离级别： <br />
ReadUncommitted：读未提交数据,该选项指示数据库读取数据时不使用任何锁。在这种情况下，事务可以读取到未提交的数据，会出现脏读，不可重复读和幻读现象。 <br />
<br />
ReadCommited： <br />
该选项只会返回"读取时间点"之前已提交的数据。因此可以避免脏读，但是会出现不可重复读，另外还会出现幻读现象。 <br />
<br />
RepeatableRead:该选项能够保证可重复读，可以避免脏读和不可重复读。 <br />
<br />
Serializable:该选项能够避免脏读、不可重复读和幻读现象，是最严格的隔离级别。 <br />
<br />
二、<span class="hilite1">spring</span>集成struts <br />
1、应用服务器没有直接调用启动<span class="hilite1">Spring</span>的方法，但是应用服务器编译运行servlet，filter,listener，所以<span class="hilite1">spring</span>提供一个listener类，在服务器初始化的时候调用该类中的方法，所以在容器中配置如下： <br />
&lt;!-- 指定<span class="hilite1">spring</span>的配置文件,多个文件之间用逗号分隔 --&gt; <br />
&lt;context-param&gt; <br />
&nbsp;&nbsp;&nbsp; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; <br />
&nbsp;&nbsp;&nbsp; &lt;param-value&gt;classpath:beans.xml&lt;/param-value&gt; <br />
&lt;/context-param&gt; <br />
&lt;!-- 启动<span class="hilite1">Spring</span>容器 --&gt; <br />
&lt;listener&gt; <br />
&nbsp;&nbsp;&nbsp; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; <br />
&lt;/listener&gt; <br />
2、我们把我们需要交给<span class="hilite1">spring</span>管理的类在beans.xml中配置： <br />
如&lt;bean name="/user/regist" <br />
class="cn.sun.ssh.web.action.UserManagerAction"&gt; <br />
&lt;property name="dao" ref="userDAO"&gt;&lt;/property&gt; <br />
&lt;/bean&gt; <br />
但是action是被引擎调用的，我们如何把需要的action交给引擎呢，通过重写struts中的requestprocessor类中的processactioncreate方法，在<span class="hilite1">spring</span>中获得action后交给引擎管理，这也是struts的一个扩展机制。 <br />
所以我们要在struts-config.xml中配置controller <br />
&lt;controller&gt; <br />
&lt;set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/&gt; <br />
&lt;/controller&gt; <br />
<br />
<br />
三、<span class="hilite1">spring</span>集成hibernate,<span class="hilite1">spring</span>和hibernate集成主要有两方面注意 <br />
1、<span class="hilite1">spring</span>集成hibernate时把dao和sessionfactory交给<span class="hilite1">spring</span>管理， 
<img src ="http://www.blogjava.net/Werther/aggbug/284637.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Werther/" target="_blank">Werther</a> 2009-06-29 17:22 <a href="http://www.blogjava.net/Werther/archive/2009/06/29/284637.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AOP的一些概念</title><link>http://www.blogjava.net/Werther/archive/2009/06/25/284145.html</link><dc:creator>Werther</dc:creator><author>Werther</author><pubDate>Thu, 25 Jun 2009 09:27:00 GMT</pubDate><guid>http://www.blogjava.net/Werther/archive/2009/06/25/284145.html</guid><wfw:comment>http://www.blogjava.net/Werther/comments/284145.html</wfw:comment><comments>http://www.blogjava.net/Werther/archive/2009/06/25/284145.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Werther/comments/commentRss/284145.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Werther/services/trackbacks/284145.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要:    切面（Aspect）： 一个关注点的模块化，这个关注点可能会横切多个对象。事务管理是J2EE应用中一个关于横切关注点的很好的例子。 在Spring AOP中，切面可以使用通用类（基于模式的风格） 或者在普通类中以 @Aspect 注解（@AspectJ风格）来实现。 &nbsp;&nbsp;<a href='http://www.blogjava.net/Werther/archive/2009/06/25/284145.html'>阅读全文</a><img src ="http://www.blogjava.net/Werther/aggbug/284145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Werther/" target="_blank">Werther</a> 2009-06-25 17:27 <a href="http://www.blogjava.net/Werther/archive/2009/06/25/284145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>