锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合小说另类图片动图,亚洲av成人一区二区三区,亚洲精品天天影视综合网http://www.tkk7.com/jinfeng_wang/category/480.htmlG-G-S,D-D-U!zh-cnThu, 20 Mar 2008 10:19:20 GMTThu, 20 Mar 2008 10:19:20 GMT60XDoclet鐨刡uild.xml鍐欐硶 zzhttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187409.htmljinfeng_wangjinfeng_wangThu, 20 Mar 2008 01:52:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187409.htmlhttp://www.tkk7.com/jinfeng_wang/comments/187409.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187409.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/187409.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/187409.html

 XDoclet鐨刡uild.xml鍐欐硶


  1. <?xml version="1.0" encoding="utf-8"?>
  2. <project name="appgen" default="web-demo" basedir=".">
  3.  
  4. <property file="build.properties" />
  5.  
  6. <path id="xdoclet.classpath">
  7. <fileset dir="${lib}">
  8. <include name="**/*.jar" />
  9. </fileset>
  10. <path location="${classes}" />
  11. </path>
  12.  
  13. <target name="clean">
  14. <delete>
  15. <fileset dir="${gen}">
  16. <include name="*.xml" />
  17. </fileset>
  18. </delete>
  19. </target>
  20.  
  21. <!-- 榪欎釜target鍙互鐢熸垚錛宻trutsconfigxml , strutsvalidationxml ,web.xml-->
  22.  
  23. <target name="web-demo" depends="clean,Spring-service-beans,Spring-action-beans,Spring-dao-beans">
  24. <taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask" classpathref="xdoclet.classpath" />
  25. <webdoclet destDir="${gen}" mergeDir="${merge}" force="false">
  26. <fileset dir="${src}">
  27. <include name="**/*Action.java" />
  28. <include name="**/*Form.java" />
  29. </fileset>
  30.  
  31. <strutsconfigxml Version="1.2" destDir="${gen}" validateXML="true"/>
  32. <strutsvalidationxml destDir="${gen}" />
  33. <deploymentdescriptor Servletspec="2.4" destDir="${gen}" />
  34.  
  35. </webdoclet>
  36. </target>
  37.  
  38. <target name="ReplaceConfigFile" depends="web-demo">
  39. <copy todir="${webinf}">
  40. <fileset dir="${gen}">
  41. <include name="struts-config.xml"/>
  42. <include name="validation.xml"/>
  43. <include name="action-beans.xml"/>
  44. <include name="dao-beans.xml"/>
  45. <include name="service-beans.xml"/>
  46. </fileset>
  47. </copy>
  48. </target>
  49. <!-- 鐢熸垚spring鐨剎ml鏂囦歡 -->
  50. <target name="Spring-service-beans" description="Spring-application-beans">
  51. <taskdef name="springdoclet" classname="xdoclet.modules.spring.SpringDocletTask" classpathref="xdoclet.classpath" />
  52. <springdoclet excludedTags="@version,@author,@todo" destDir="gen" verbose="true" addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}">
  53. <fileset dir="src" includes="**/*ServiceImpl.java"/>
  54. <springxml destinationFile="service-beans.xml" destDir="gen"/>
  55. </springdoclet>
  56. </target>
  57.  
  58.  
  59. <!-- 鐢熸垚spring鐨剎ml鏂囦歡 -->
  60. <target name="Spring-action-beans" description="Spring-servlet-beans">
  61. <taskdef name="springdoclet" classname="xdoclet.modules.spring.SpringDocletTask" classpathref="xdoclet.classpath" />
  62. <springdoclet excludedTags="@version,@author,@todo" destDir="gen" verbose="true" addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}">
  63. <springxml destinationFile="action-beans.xml" destDir="gen"/>
  64. <fileset dir="src" includes="**/*Action.java"/>
  65. </springdoclet>
  66. </target>
  67.  
  68.  
  69. <!-- 鐢熸垚spring鐨剎ml鏂囦歡 -->
  70. <target name="Spring-dao-beans" description="Spring-servlet-beans">
  71. <taskdef name="springdoclet" classname="xdoclet.modules.spring.SpringDocletTask" classpathref="xdoclet.classpath" />
  72. <springdoclet excludedTags="@version,@author,@todo" destDir="gen" verbose="true" addedTags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}">
  73. <springxml destinationFile="dao-beans.xml" destDir="gen"/>
  74. <fileset dir="src" includes="**/*DAOIbatis.java"/>
  75. </springdoclet>
  76. </target>
  77.  
  78. </project>
  79.  


錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳錛濓紳


  1. /**
  2. * @spring.bean id="UserDAO"
  3. * @spring.property name="dataSource" ref="dataSource"
  4. * @spring.property name="sqlMapClient" ref="sqlMapClient"
  5. *
  6. * @author Conan
  7. *
  8. */
  9. public class UserDAOIbatis extends BaseDAOIBatis implements UserDAO {....}


-------------------------------------------


  1. /**
  2. * @spring.bean id="UserService"
  3. * @spring.property name="userDao" ref="UserDAO"
  4. *
  5. * @author Conan
  6. *
  7. */
  8. public class UserServiceImpl extends BaseManager implements UserService {...}



 ---------------------------------------------


  1. /**
  2. *
  3. * @struts.action path="/add" name="UserForm" input="/add.jsp"
  4. * type="org.springframework.web.struts.DelegatingActionProxy"
  5. * validate="true" scope="request"
  6. *
  7. * @struts.action-forward name="success" path="/success.jsp" redirect="true"
  8. * @struts.action-forward name="failure" path="/failure.jsp" redirect="true"
  9. *
  10. * @struts.action-form name="UserForm"
  11. *
  12. * @spring.bean
  13. * name="/add"
  14. * @spring.property
  15. * name="userService"
  16. * ref="UserService"
  17. *
  18. */
  19. public final class AddAction extends BaseAction {...}


------------------------------------------


  1. /**
  2. * @struts.form name="UserForm"
  3. */
  4. public class UserForm extends BaseForm{
  5.  
  6. /**
  7. * @struts.validator type="required"
  8. * @struts.validator type="mask" msgkey="error.age"
  9. * @struts.validator-var name="mask" value="^[0-9]*$"
  10. */
  11. public void setAge(Integer age) {
  12. this.age = age;
  13. }
  14.  
  15. }






jinfeng_wang 2008-03-20 09:52 鍙戣〃璇勮
]]>
XDoclet Spring+Struts HowTo zzhttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187406.htmljinfeng_wangjinfeng_wangThu, 20 Mar 2008 01:42:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187406.htmlhttp://www.tkk7.com/jinfeng_wang/comments/187406.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2008/03/20/187406.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/187406.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/187406.html

For all those out there using Spring together with Struts, i created a small howTo regarding automatic generation of relevant files, especially the boring action-servlet-xml file which must be in synch with your struts-config.xml, at least for all Struts actions which should be injected by Spring.

Lets start with the Action class:

/**
* Action to delete a Client
* Date: 09.02.2005
* Time: 15:29:15
*
* @author Logemann - Logentis e.K. (ml@logentis.de)
* @version $Id$
* @struts.action path="clientDelete" validate="false"
* type="org.springframework.web.struts.DelegatingActionProxy"
* name="emptyform"
* @struts.action-forward name="back"
* path="/clientManager.html" redirect="true"
* @spring.bean name="clientDelete"
*/
public class ClientDeleteAction extends Action {

ClientManager clientManagerService;



/**

* Spring injection

*

* @param clientManagerService clientManagerService

* @spring.property ref="clientManagerService"

*/

public void setClientManagerService(ClientManager clientManagerService) {

this.clientManagerService = clientManagerService;

}

[..]


With this tags, the ant build target outlined below will create a struts-config.xml and the necessary action-servlet.xml needed by Spring. Lets see how the target looks:

<path id="classpath">

<fileset dir="c:/xdoclet-1.2.2" includes="*.jar"/>
<fileset dir="c:/j2sdkee1.3.1/lib" includes="*.jar"/>
<fileset dir="c:/struts/lib" includes="struts.jar"/>
</path>

<taskdef name="springdoclet"
classname="xdoclet.modules.spring.SpringDocletTask"
classpathref="classpath"/>

<taskdef name="webdoclet"
classname="xdoclet.modules.web.WebDocletTask"
classpathref="classpath"/>

<target name="myTest">
<webdoclet destDir="c:\" force="true" verbose="true">
<fileset dir="${src.dir}">
<include name="**/*Form.java" />
<include name="**/*Action.java" />
<include name="**/*Servlet.java" />
</fileset>
<strutsconfigxml version="1.1" validateXml="true"/>
</webdoclet>

<springdoclet destDir="c:\" verbose="true">
<fileset dir="${src.dir}">
<include name="**/*Action.java" />
</fileset>
<springxml destinationFile="action-servlet.xml"/>
</springdoclet>
</target>

Be sure to modify the classpath definition and the destDir values of springdoclet and webdoclet to suit your needs. Right now the Spring task only searches for Actions in order to create action-servlet.xml, if you also want to create your normal service beans like ClientManagerService, you should create another springdoclet task and output things to applicationContext.xml if you like.

But this is mostly users choice, as you know, Spring supports from one to many bean definition files and its up to you how you want to have your spring xml world.

This will be created when you run the mentioned target:

(action-servlet.xml)


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans
default-autowire="no"
default-lazy-init="false"
default-dependency-check="none"
>

<bean
name="clientDelete"
class="de.logentis.versysng.action.clientmanager.ClientDeleteAction"
>

<property name="clientManagerService">

<ref bean="clientManagerService"/>
</property>

</bean>

<!--
To include additional bean definitions for Spring in the generated
application context file, add a file to your XDoclet merge directory
called spring-beans.xml that contains the <bean></bean> markup.
-->
</beans>


(struts-config.xml)


<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>

<!-- ========== Data Sources Definitions =================================== -->
<!--
Define your Struts data sources in a file called struts-data-sources.xml and place
it in your merge directory.
-->

<!-- ========== Form Bean Definitions =================================== -->
<form-beans>

<!--
If you have non XDoclet forms, define them in a file called struts-forms.xml and
place it in your merge directory.
-->
</form-beans>

<!-- ========== Global Exceptions Definitions =================================== -->
<!--
Define your exceptions in a file called global-exceptions.xml and place
it in your merge directory.
-->

<!-- ========== Global Forward Definitions =================================== -->
<!--
Define your forwards in a file called global-forwards.xml and place
it in your merge directory.
-->

<!-- ========== Action Mapping Definitions =================================== -->
<action-mappings>
<action
path="clientDelete"
type="org.springframework.web.struts.DelegatingActionProxy"
name="emptyform"
scope="request"
unknown="false"
validate="false"
>
<forward
name="back"
path="/clientManager.html"
redirect="true"
/>
</action>

<!-- If you have non XDoclet actions, define them in a file called struts-actions.xml and place it in your merge directory. -->
</action-mappings>

<!-- Define your Struts controller in a file called struts-controller.xml and place it in your merge directory. -->

<!-- Define your Struts message-resources in a file called struts-message-resources.xml and place it in your merge directory. -->

<!-- Define your Struts plugins in a file called struts-plugins.xml and place it in your merge directory. -->

</struts-config>



jinfeng_wang 2008-03-20 09:42 鍙戣〃璇勮
]]>
Pro Spring: Spring and EJB (zz)http://www.tkk7.com/jinfeng_wang/archive/2005/03/18/2192.htmljinfeng_wangjinfeng_wangFri, 18 Mar 2005 06:35:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/18/2192.htmlhttp://www.tkk7.com/jinfeng_wang/comments/2192.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/18/2192.html#Feedback1http://www.tkk7.com/jinfeng_wang/comments/commentRss/2192.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/2192.html SummaryIn traditional J2EE applications, Enterprise JavaBeans (EJB) often forms the cornerstone of an application'...  闃呰鍏ㄦ枃

jinfeng_wang 2005-03-18 14:35 鍙戣〃璇勮
]]>
Pro Spring鐨勭洰褰?/title><link>http://www.tkk7.com/jinfeng_wang/archive/2005/03/06/1768.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Sun, 06 Mar 2005 06:46:00 GMT</pubDate><guid>http://www.tkk7.com/jinfeng_wang/archive/2005/03/06/1768.html</guid><wfw:comment>http://www.tkk7.com/jinfeng_wang/comments/1768.html</wfw:comment><comments>http://www.tkk7.com/jinfeng_wang/archive/2005/03/06/1768.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/jinfeng_wang/comments/commentRss/1768.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/jinfeng_wang/services/trackbacks/1768.html</trackback:ping><description><![CDATA[PART 1 鈻?鈻?鈻?Getting Started with Spring<BR>CHAPTER 1 Introducing Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3<BR>CHAPTER 2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<BR>CHAPTER 3 The Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35<BR>PART 2 鈻?鈻?鈻?Spring Basics<BR>CHAPTER 4 Introducing Inversion of Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49<BR>CHAPTER 5 Beyond the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93<BR>PART 3 鈻?鈻?鈻?Aspect Oriented Programming<BR>with Spring<BR>CHAPTER 6 Introducing Spring AOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157<BR>CHAPTER 7 More on Spring AOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205<BR>PART 4 鈻?鈻?鈻?Data Access with Spring<BR>CHAPTER 8 Spring JDBC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249<BR>CHAPTER 9 Using Hibernate in Spring Applications . . . . . . . . . . . . . . . . . . . . . . . 279<BR>CHAPTER 10 iBATIS Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311<BR>vi 鈻燙ONTENTS AT A GLANCE<BR>PART 5 鈻?鈻?鈻?Spring in the Middle Tier<BR>CHAPTER 11 Designing and Implementing Spring-Based Applications . . . . . . 353<BR>CHAPTER 12 Transaction Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395<BR>CHAPTER 13 Spring and J2EE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439<BR>CHAPTER 14 Job Scheduling with Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487<BR>CHAPTER 15 Mail Support in Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517<BR>CHAPTER 16 Using Spring Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549<BR>PART 6 鈻?鈻?鈻?Web Applications with Spring<BR>CHAPTER 17 Web Applications with Spring MVC . . . . . . . . . . . . . . . . . . . . . . . . . . 599<BR>CHAPTER 18 Beyond JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645<BR>CHAPTER 19 Spring and Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679<BR>PART 7 鈻?鈻?鈻?Appendixes<BR>APPENDIX A Testing with Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697<BR>APPENDIX B The Spring Rich Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711<BR>APPENDIX C Spring IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729<BR>APPENDIX D The Future of Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743<img src ="http://www.tkk7.com/jinfeng_wang/aggbug/1768.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-03-06 14:46 <a href="http://www.tkk7.com/jinfeng_wang/archive/2005/03/06/1768.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Spring Transactionhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/04/1683.htmljinfeng_wangjinfeng_wangFri, 04 Mar 2005 06:15:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/04/1683.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1683.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/04/1683.html#Feedback1http://www.tkk7.com/jinfeng_wang/comments/commentRss/1683.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1683.htmlSpring Transaction錛氶氳繃Template+Callback鏈哄埗錛屽疄鐜板鍚勭浜嬪姟鐨勭粺涓灝佽銆?/SPAN>

 

<bean id="transactionManager" //瀵?/SPAN>JDBC Transaction鐨勫皝瑁?/SPAN>

       class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

       <property name="dataSource">

              <ref bean="dataSource"/>

       </property>

</bean>

 

<bean id="transactionManager" //瀵?/SPAN>Hibernate浜嬪姟鐨勫皝瑁?/SPAN>

       class="org.springframework.orm.hibernate.HibernateTransactionManager">

       <property name="sessionFactory">

              <ref bean="sessionFactory"/>

       </property>

</bean>

 

<bean id="transactionManager"http://瀵?/SPAN>JDO浜嬪姟鐨勫皝瑁?/SPAN>

       class="org.springframework.orm.jdo.JdoTransactionManager">

       <property name="persistenceManagerFactory">

              <ref bean="persistenceManagerFactory"/>

       </property>

</bean>

 

<bean id="transactionManager" //瀵?/SPAN>JTA 浜嬪姟鐨勫皝瑁?/SPAN>

       class="org.springframework.transaction.jta.JtaTransactionManager">

       <property name="transactionManagerName">

              <value>java:/TransactionManager</value>

       </property>

</bean>

 

<bean id="courseService"http://鍒╃敤AOP錛屽皢TransactionManager鍜屾櫘閫氱殑Service緙栫粐璧鋒潵錛屽疄鐜頒簨鍔°?/SPAN>

       class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

       <property name="proxyInterfaces">//緙栫粐鍚庡澶栫殑鎺ュ彛

              <list>

                     <value>com.springinaction.training.service.CourseService</value>

              </list>

       </property>

       <property name="target">//鐩爣

              <ref bean="courseServiceTarget"/>

       </property>

       <property name="transactionManager">//妞嶅叆鐨勪簨鍔$鐞嗚?/SPAN>

              <ref bean="transactionManager"/>

       </property>

       <property name="transactionAttributeSource">//浜嬪姟鐨勫弬鏁幫紙闅旂搴︼紝鏂規硶鍚嶇瓑錛?/SPAN>

              <ref bean="attributeSource"/>

       </property>

</bean>



]]>
Spring灝佽Hibernatehttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1654.htmljinfeng_wangjinfeng_wangThu, 03 Mar 2005 08:58:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1654.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1654.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1654.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1654.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1654.htmlSpring灝佽Hibernate錛?/SPAN>

  鏈変袱縐嶆墜孌碉細1銆佷嬌鐢?/SPAN>HibernateTemplate錛?/SPAN>2銆佺戶鎵?/SPAN>HibernateDaoSupport錛堝疄闄呬笂錛?/SPAN>HibernateDaoSupport鏈韓灝辨槸瀵?/SPAN>HibernateTemplate鐨勪竴涓皝瑁咃級

   涓鍒囧敖鍦ㄤ唬鐮佷腑錛屾煡鐪?/SPAN>API鍞夛紒

娉ㄦ剰錛歨ibernate 2.X鍜宧ibernate3.X鐨勫尯鍒紝鎴戠敤鐨勬槸2.X 銆?nbsp; 
 

package com.company.example.dao;

 

import java.util.List;

 

import com.company.example.model.Student;

 

public interface StudentDao {

    public abstract Student getStudent(final Integer id);

    public abstract void updateStudent(Student student);

    public abstract List findStudentsByLastName(String lastName);

}

==================

package com.company.example.dao.hibernateImpl;

 

import java.util.List;

 

import net.sf.hibernate.Hibernate;

import net.sf.hibernate.HibernateException;

import net.sf.hibernate.Session;

 

import org.springframework.orm.hibernate.HibernateCallback;

import org.springframework.orm.hibernate.HibernateTemplate;

 

import com.company.example.dao.StudentDao;

import com.company.example.model.Student;

 

public class StudentDaoHibernate implements StudentDao {

    HibernateTemplate hibernateTemplate;

 

    public static void main(String[] args) {

    }

 

    public HibernateTemplate getHibernateTemplate() {

        return hibernateTemplate;

    }

 

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {

        this.hibernateTemplate = hibernateTemplate;

    }

 

    public Student getStudent(final Integer id) {

        return (Student) hibernateTemplate.execute(new HibernateCallback() {

            public Object doInHibernate(Session session)

                    throws HibernateException {

                return session.load(Student.class, id);

            }

        });

    }

 

    public Student getStudent2(Integer id) {

        return (Student) hibernateTemplate.load(Student.class, id);

    }

 

    public void updateStudent(Student student) {

        hibernateTemplate.update(student);

    }

 

    public List findStudentsByLastName(String lastName) {

        return hibernateTemplate.find("from Student student "

                + "where student.lastName = ?", lastName, Hibernate.STRING);

    }

}

public class StudentDaoHibernate extends HibernateDaoSupport

implements StudentDao {

 ...........

}
======The Spring XML Configuration===========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"<beans>
 <bean id="dataSource"
  class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName">
   <value>java:comp/env/jdbc/trainingDatasource</value>
  </property>
 </bean>
 
 <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource"/>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
   </props>
  </property>
  <property name="mappingResources">
   <list> <!--list of each hbm.xml-->
    <value>Student.hbm.xml</value>
    <value>Course.hbm.xml</value>
   </list>
  </property>
  <property name="mappingDirectoryLocations">
   <list>
    <!--list the directory of the hbm.xml, including each xml file in the dir-->
    <value>classpath:/com/springinaction/training/model</value>
   </list>
  </property>
 </bean>
 
 <bean id="hibernateTemplate"
  class="org.springframework.orm.hibernate.HibernateTemplate">
  <property name="sessionFactory">
   <ref bean="sessionFactory"/>
  </property>
 </bean>

 <bean id="studentDao" class="com.company.example.dao.hibernateImpl.StudentDaoHibernate">
  <property name="hibernateTemplate">
   <ref bean="hibernateTemplate"/>
  </property>
 </bean>

 <bean id="courseDao" class="com.company.example.dao.hibernateImpl.CourseDaoHibernate">
  <property name="hibernateTemplate">
   <ref bean="hibernateTemplate"/>
  </property>
 </bean>
</beans>



]]>
Spring JDBC DAO鐨勪袱涓猠xamplehttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1647.htmljinfeng_wangjinfeng_wangThu, 03 Mar 2005 06:40:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1647.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1647.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1647.html#Feedback3http://www.tkk7.com/jinfeng_wang/comments/commentRss/1647.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1647.html闃呰鍏ㄦ枃

jinfeng_wang 2005-03-03 14:40 鍙戣〃璇勮
]]>
Spring DAO鐨勫摬瀛?/title><link>http://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1644.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Thu, 03 Mar 2005 05:04:00 GMT</pubDate><guid>http://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1644.html</guid><wfw:comment>http://www.tkk7.com/jinfeng_wang/comments/1644.html</wfw:comment><comments>http://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1644.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.tkk7.com/jinfeng_wang/comments/commentRss/1644.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/jinfeng_wang/services/trackbacks/1644.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 2.0; mso-char-indent-size: 10.5pt" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">Spring DAO</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">鐨勫摬瀛︼細</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 2.0; mso-char-indent-size: 10.5pt" align=left><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">灝佽鎵鏈夌殑鏁版嵁搴撹闂疄鐜幫紝鍖呮嫭</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">JDBC,JDO,Hibernate</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">絳夈?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">Spring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">鐨勫紓甯鎬竴鑸兘鏄?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">RuntimeException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛屾暟鎹闂殑鏍瑰紓甯告槸</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛屾墍鏈夌殑</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">Spring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">鐨勬暟鎹闂紓甯擱兘緇ф壙</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">銆傛澶?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">鐨?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">nestedRuntimeException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">瀛愮被涓紝宸茬粡灝嗘墍鏈夌殑寮傚父鏍堥兘榪涜浜嗚褰曘?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">Spring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">鐨?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DAO</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">寮傚父瀵規墍鏈夊簳灞傜殑</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DAO</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">璁塊棶瀹炵幇灞傜殑寮傚父榪涜浜嗙粺涓鐨勫皝瑁咃紝騫剁粰鍑轟簡鏇翠負鏈夋剰涔夌殑寮傚父銆?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">CleanupFailureDataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭竻闄ゅけ璐ュ紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataAccessResourceFailureException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氳祫婧愯闂紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataIntegrityViolationException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氬畬鏁存х害鏉熷紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DataRetrievalFailureException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭暟鎹幏鍙栧紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">DeadlockLoserDataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭閿佽闂紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">IncorrectUpdateSemanticsDataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭洿鏂板嚭閿欏紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">InvalidDataAccessApiUsageException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭棤鏁堟暟鎹闂?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">API</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">浣跨敤寮傚父</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">InvalidDataAccessResourceUsageException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氭棤鏁堟暟鎹闂祫婧愪嬌鐢ㄥ紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">OptimisticLockingFailureException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氫箰瑙傞攣澶辮觸寮傚父</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">TypeMismatchDataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氱被鍨嬪尮閰嶅け璐ュ紓甯?/SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt"><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">UncategorizedDataAccessException</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-bidi-font-size: 10.5pt">錛氬叾浠栧師鍥犲紓甯?BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p><BR><BR><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">Spring</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">浣跨敤</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">Template</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">鍜?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">Callback</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">妯″紡瀹屾垚浜嗗搴曞眰瀹炵幇鐨勭粺涓灝佽錛屽叾涓?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">Template</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">璐熻矗瀹屾垚閭d簺閫氱敤鐨勫姛鑳斤紙澶勭悊浜嬪姟銆佺鐞嗚祫婧愩佸鐞嗗紓甯革級錛?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">Callback</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">鍒欏畬鎴愬彉鍖栫殑閭i儴鍒嗗唴瀹癸紙鍒涘緩</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">statement</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">銆佽瀹氬弬鏁?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">parameter</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">銆佺敓鎴愭暟鎹泦</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">result</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">錛夈傚弬鑰冨浘</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">4.2</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">銆?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋">4.3</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-ansi-language: EN-US; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">澶噸瑕佷簡銆?/SPAN></o:p></SPAN></P><img src ="http://www.tkk7.com/jinfeng_wang/aggbug/1644.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-03-03 13:04 <a href="http://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1644.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Spring AOP涓殑Introductionhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1637.htmljinfeng_wangjinfeng_wangThu, 03 Mar 2005 02:49:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1637.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1637.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/03/1637.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1637.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1637.htmlSpring AOP涓殑Introduction錛?/SPAN>

姝e鍓嶉潰宸茬粡鎻愬埌鐨勶紝Introduction鍜屽墠闈㈢殑鍥涗釜advice鏄湁寰堝ぇ鐨勫尯鍒殑錛?/SPAN>introduction鐢ㄤ簬緇?/SPAN>target寮曞叆鏂扮殑鎺ュ彛錛堜緥濡傞攣錛岀姸鎬佺瓑鍔熻兘錛夛紝鐢熸垚涓涓?/SPAN>mix-in鐨勬帴鍙c傝屾櫘閫氱殑advice鍙槸鍦ㄥ師鏈夋帴鍙e熀紜涓婂鍔犻檮鍔犲唴瀹廣?/SPAN>

鍦?/SPAN>Spring涓紝瀹屾垚涓涓?/SPAN>introduction闇瑕佷笁涓唴瀹癸細1銆佸皢瑕佹坊鍔犵殑鏂版帴鍙g殑瀹氫箟錛?/SPAN>2銆佽鏂版帴鍙g殑瀹炵幇錛屽湪瀹炵幇鐨?/SPAN>class涓紝蹇呴』瀹炵幇Spring鐨?/SPAN>IntroductionInterceptor鎺ュ彛錛?/SPAN>Spring in action鍘熸枃鏈夎錛夛紝3銆?/SPAN>IntroductionAdvisor鎺ュ彛鐨勫疄鐜?/SPAN>銆?/SPAN>

public interface IntroductionInterceptor extends MethodInterceptor {

  boolean implementsInterface(Class intf);

java.lang.Object invoke(MethodInvocation invocation) //姝ゆ柟娉曟潵婧愪簬MethodInterceptor

}

鍏朵腑implementsInterface鏂規硶榪斿洖涓涓?/SPAN>boolean鍊鹼紝姝ゆ柟娉曠敤浜庡垽鏂introduction瀹炵幇鏄惁瀹炵幇浜嗘煇涓帴鍙b曗?/SPAN>intf鍙傛暟銆傛墍鏈夊intf鎺ュ彛鐨勮皟鐢ㄩ兘浼氳漿鍙戠粰invoke鏂規硶錛岀敱invoke鏂規硶瀹屾垚鐩稿簲鐨勪換鍔°備笅闈㈢粰鍑轟緥瀛愶紙緇欐煇涓被娣誨姞鏄惁auditable鍔熻兘錛夛細

            public interface Auditable {//1銆?/SPAN>auditable鎺ュ彛鐨勫畾涔?/SPAN>

void setLastModifiedDate(Date date);

Date getLastModifiedDate();

}

public class AuditableMixin

implements IntroductionInterceptor, Auditable {//2銆?/SPAN>auditable鎺ュ彛鐨勫疄鐜幫紝鍚屾椂瑕佸疄鐜?/SPAN>IntroductionInterceptor鎺ュ彛

public boolean implementsInterface(Class intf) {

return intf.isAssignableFrom(Auditable.class);  // AuditableMixin瀹炵幇浜?/SPAN>Auditable綾葷殑鍔熻兘

}

public Object invoke(MethodInvocation m) throws Throwable {

if (implementsInterface(m.getMethod().getDeclaringClass())) {

//瀵?/SPAN>invoke鐨勫弬鏁?/SPAN>m榪涜鍒ゆ柇錛屽綋鍓嶇殑璋冪敤鏄惁鍦?/SPAN>implementsInterface鑼冨洿鍐咃紝鍗籌紝褰撳墠鐨勮皟鐢ㄦ槸鍚︽槸auditable鎺ュ彛涓殑鏂規硶錛?/SPAN>

return m.getMethod().invoke(this, m.getArguments());

//榪欓噷鐨?/SPAN>this灝辨槸鑷繁錛岃皟鐢ㄥ紩鍏ョ殑鏂規硶錛堝睘浜?/SPAN>auditable鎺ュ彛鐨勬柟娉曪級錛岃繖鏍蜂篃灝辯粰target娣誨姞浜嗘柊鐨?/SPAN>auditable鎺ュ彛銆?/SPAN>

} else {

return m.proceed();//鍏朵粬鏂規硶鐨勮皟鐢ㄣ?/SPAN>

}

}

private Date lastModifiedDate; //瀹炵幇auditable鎺ュ彛銆?/SPAN>

public Date getLastModifiedDate() {

return lastModifiedDate;

}

public void setLastModifiedDate(Date lastModifiedDate) {

this.lastModifiedDate = lastModifiedDate;

}

}

鍦?/SPAN>Spring涓紝闄や簡涓婇潰鐩存帴瀹炵幇IntroductionInterceptor鎺ュ彛涔嬪錛岃繕鍙互閫氳繃緇ф壙DelegatingIntroductionInterceptor綾誨疄鐜般傚叾涓?/SPAN>DelegatingIntroductionInterceptor緇欏嚭浜?/SPAN>IntroductionInterceptor鎺ュ彛涓殑涓や釜鏂規硶錛?/SPAN>implementsInterface錛?/SPAN>invoke錛夌殑榛樿瀹炵幇錛屼綘浠呴渶瑕佸疄鐜?/SPAN>auditable鎺ュ彛鍗沖彲銆?/SPAN>

閫氳繃璺熻釜Spring婧愪唬鐮佸彲浠ュ彂鐜幫細DelegatingIntroductionInterceptor鐨?/SPAN>implementsInterface 錛堝湪IntroductionInfoSupport綾諱腑錛夊拰invoke鏂規硶涓庝笂闈㈢殑浠g爜鐨勫艦寮忓熀鏈竴鑷淬備笅闈㈡槸鍒╃敤DelegatingIntroductionInterceptor鍐欏嚭鐨?/SPAN>AuditableMixin錛?/SPAN>

public class AuditableMixin

extends DelegatingIntroductionInterceptor implements Auditable {

private Date lastModifiedDate;

public Date getLastModifiedDate() {

return lastModifiedDate;

}

public void setLastModifiedDate(Date lastModifiedDate) {

this.lastModifiedDate = lastModifiedDate;

}      

}

    娉ㄦ剰鍒頒竴鐐癸細涓婇潰鐨勪袱涓?/SPAN>AuditableMixin鐨勫疄鐜伴兘浠呬粎鏄粰Target娣誨姞琛屼負錛屼絾鏄湭鏇炬敼鍙?/SPAN>Target鐨勫師鏈夎涓猴紙鍥犱負鍦?/SPAN>invoke鏂規硶鐨勫疄鐜頒腑錛岃繕鏄細杞彂緇?/SPAN>Target錛夈傚鏋滈渶瑕佹敼鍙?/SPAN>Target鐨勮涓?SPAN style="COLOR: red">錛堜緥濡傜粰Target澧炲姞lock鎺ュ彛錛屼竴鏃﹀浜?/SPAN>locked鐘舵侊紝閭d箞鍐嶈皟鐢?/SPAN>Target鐨勬柟娉曞氨浼氬嚭鐜板紓甯革級錛岃繖灝遍渶瑕佽嚜宸卞啓浠g爜淇敼invoke鏂規硶銆?/SPAN>

public class ImmutableMixin

extends DelegatingIntroductionInterceptor implements Immutable {

private boolean immutable;

public void setImmutable(boolean immutable) {

this.immutable = immutable;

}

public Object invoke(MethodInvocation mi) throws Throwable {

String name = mi.getMethod().getName();

if (immutable && name.indexOf("set") == 0) { //榪欓噷涓鏃﹀凡緇忔槸immutable浜嗭紝閭d箞灝變笉鍙互璋冪敤setXXX鏂規硶浜嗭紝榪欎篃灝辨敼鍙樹簡Target鐨勮涓猴紝鑰屼笉鏄墠闈㈢殑浠呭鍔犳帴鍙c?/SPAN>

throw new IllegalModificationException();

}

return super.invoke(mi);

}

}

 

Spring涓殑Introduction闇瑕佹湁鑷繁鐨?/SPAN>advisor: IntroductionAdvisor

鍓╀笅鐨勪篃灝辨槸鍜屽墠闈竴鏍風殑xml鏂囦歡鐨勭紪鍐欎簡銆?BR>

Spring涓嬌鐢↖ntroduction闇瑕佹敞鎰忕殑闂錛?BR>    鐢變簬Spring浣跨敤鐨勬槸鍔ㄦ丄OP,騫舵病鏈夎薄AspectJ浣跨敤闈欐佺殑浠g爜棰勭紪璇戠殑鏂瑰紡鐢熸垚AOP浠g爜錛屽洜姝ゅ彧鏈変綘浠嶴pring鐨凚eanFactory涓緱鍒扮殑Introduction Bean鎵嶄細宸茬粡琚玦ntroducted錛岃岀洿鎺ュ湪浠g爜涓璶ew鍑烘潵鐨則arget瀵硅薄鍒欎笉鍏鋒湁Intorduction鍔熻兘銆?浣犲彲浠ヤ嬌鐢ㄤ竴涓狥actory錛屽皝瑁呭Introduction鐨勫垱寤恒?/SPAN>

]]>
Spring AOP涓殑pointcuthttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1615.htmljinfeng_wangjinfeng_wangWed, 02 Mar 2005 09:33:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1615.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1615.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1615.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1615.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1615.htmlSpring AOP涓殑pointcut錛?/SPAN>

PointCuts鐢ㄤ簬瀹氫箟鎵闇瑕佲滄嫤鎴濈殑class鍙婂叾method銆傚垎涓洪潤鎬併佸姩鎬佷袱縐?/SPAN>pointcut銆傚叾涓潤鎬?/SPAN>pointcuts浠呭拰class name, method name鐩稿叧錛屽彲浠ュ湪閰嶇疆鏂囦歡涓氳繃姝e垯琛ㄨ揪寮忚繘琛岄儴緗詫紝鍥犳瀹冧滑閮藉彲浠ュ湪榪愯鍓嶈繘琛岀‘璁ゃ傝屽姩鎬?/SPAN>pointcuts鍒欓渶瑕佽冭檻鍒版柟娉曠殑鍙傛暟錛屽湪榪愯鏃跺姩鎬佺殑紜pointcuts銆備竴鑸潵璇達紝閮芥槸鏍規嵁method鍜?/SPAN>class鐨勫悕瀛楁潵榪涜銆傚叾娑夊強鍒扮殑鎺ュ彛濡備笅瀹氫箟錛?/SPAN>

public interface Pointcut {

    ClassFilter getClassFilter();

    MethodMatcher getMethodMatcher();

}

public interface ClassFilter {

    boolean matches(Class clazz);

}

public interface MethodMatcher {

    boolean matches(Method m, Class targetClass);

    boolean isRuntime();

    boolean matches(Method m, Class targetClass, Object[] args);

}

涓ょ闈欐?/SPAN>pointcut鐨勫疄鐜幫細

NameMatchMethodPointcut錛氬彧鑳藉鏂規硶鍚嶈繘琛屽垽鍒?/SPAN>

RegexpMethodPointcut錛氬彲浠ュ綾誨悕銆佹柟娉曞悕浣跨敤姝e垯琛ㄨ揪寮忓垽鍒?/SPAN>

<beans>

       <bean id="maidServiceTarget"

              class="com.springinaction.chapter03.cleaning.MaidService"/>

      

       <bean id="queryInterceptor" class="com.springinaction.chapter03.cleaning.QueryInterceptor"/>

 

       <bean id="queryPointcutAdvisor"

              class="org.springframework.aop.support.RegExpPointcutAdvisor">

              <property name="pattern">

                     <value>.*get.+By.+</value>

              </property>

              <property name="advice">

                     <ref bean="queryInterceptor"/>

              </property>

       </bean>

      

       <bean id="maidService"

              class="org.springframework.aop.framework.ProxyFactoryBean">

              <property name="proxyInterfaces">

                     <value>com.springinaction.chapter03.cleaning.MaidService</value>

              </property>

              <property name="interceptorNames">

                     <list>

                            <value>queryPointcutAdvisor</value>

                     </list>

              </property>

              <property name="target">

                     <value ref="maidServiceTarget">

              </property>

       </bean>

</beans>

涓縐嶅姩鎬?/SPAN>pointcut鐨勫疄鐜幫細

ControlFlowPointcut錛氭牴鎹綋鍓嶈繍琛屾爤鐨勬儏鍐碉紝鍐沖畾褰撳墠鐨?/SPAN>advice鏄惁闇瑕佽瑙﹀彂銆傚洜涓哄畠瀹屽叏鍩轟簬榪愯鏃舵爤鐨勬儏鍐靛仛鍐崇瓥錛屾墍浠ヨ繍琛岄熷害鑲畾浼氬彉鎱€?/SPAN>

<beans>

       <bean id="myServiceTarget" class="MyServiceImpl"/>

      

       <bean id="servletInterceptor" class="MyServletInterceptor"/>

      

       <bean id="servletPointcut" class="org.springframework.aop.support.ControlFlowPointcut">

              <constructor-arg>

                     <value>javax.servlet.http.HttpServlet</value>

              </constructor-arg>

       </bean>

 

       <bean id="servletAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">

              <property name="advice">

                     <ref bean="servletInterceptor"/>

              </property>

              <property name="pointcut">

                     <ref bean="servletPointcut"/>

              </property>

       </bean>

       <bean id="service" class="org.springframework.aop.framework.ProxyFactoryBean">

              <property name="proxyInterfaces">

                     <value>MyService</value>

              </property>

              <property name="interceptorNames">

                     <list>

                            <value>servletAdvisor</value>

                     </list>

              </property>

              <property name="target">

                     <value ref="myServiceTarget">

              </property>

       </bean>

</beans>



]]>
SpringAOP涓殑advisorhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1614.htmljinfeng_wangjinfeng_wangWed, 02 Mar 2005 09:32:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1614.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1614.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1614.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1614.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1614.htmlSpringAOP涓殑advisor錛?/SPAN>

鍓嶉潰宸茬粡鎻愬埌錛?/SPAN>advisor鏄槸PointCut鍜?/SPAN>Advice鐨勭患鍚堜綋錛屽畬鏁存弿榪頒簡涓涓?/SPAN>advice灝嗕細鍦?/SPAN>pointcut鎵瀹氫箟鐨勪綅緗瑙﹀彂銆備篃灝辨槸璇達紝瀹冨寘鍚簡pointcut鍜?/SPAN>advice涓ら」鍐呭錛岃繖涓ら」鍐呭鍒欑敤浜庡垎鍒粰鍑?/SPAN>advice璋冪敤鎵鍙戠敓鐨勪綅緗拰鍙戠敓鐨勫唴瀹廣傚叾鎺ュ彛濡備笅錛?/SPAN>

public interface PointcutAdvisor {

Pointcut getPointcut();

Advice getAdvice();

}

]]>
Spring AOP涓殑鍥涗釜Advicehttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1612.htmljinfeng_wangjinfeng_wangWed, 02 Mar 2005 09:31:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1612.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1612.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1612.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1612.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1612.html 

1銆?SPAN style="FONT: 7pt 'Times New Roman'">  around advice錛氭墍鏈?/SPAN>around advice蹇呴』瀹炵幇MethodInterceptor鎺ュ彛錛屾敞鎰?/SPAN>invoke鏂規硶鐨勫弬鏁?/SPAN>invocation鏄?/SPAN>MethodInvocation鎺ュ彛錛屽湪姝や腑鍖呭惈浜嗚澶氫俊鎭紝鍖呮嫭鍏舵墍灝佽鐨勬柟娉曞強鍏跺弬鏁幫紝AOP proxy銆?/SPAN>Jointcut絳夈?/SPAN>

public interface MethodInterceptor extends Interceptor {

                  Object invoke(MethodInvocation invocation) throws Throwable;

}

    鍦ㄥ疄鐜?/SPAN>around advice鏃訛紝鍜?/SPAN>before advice銆?/SPAN>after advice鏈夌潃涓や釜寰堝ぇ鐨勫尯鍒細1銆佸繀欏誨湪invoke鏂規硶涓皟鐢?/SPAN>MethodInvocation.proceed()錛岃繖鏍鋒墠鑳藉皢鎵鏈夎皟鐢ㄥ歡緇笅鍘伙紝璋冪敤target瀵硅薄鐨?/SPAN>method錛?/SPAN>2銆佸繀欏昏嚜宸辮繑鍥炰竴涓?/SPAN>object錛岃object鐢氳嚦鍙互涓?/SPAN>target鈥檚 method鐨勮繑鍥炲間笉涓鏍楓?/SPAN>

 

2銆?SPAN style="FONT: 7pt 'Times New Roman'">  before advice錛氬湪jointcut鎵ц涔嬪墠錛岃繍琛?/SPAN>advice銆傚繀欏誨疄鐜?/SPAN>MethodBeforeAdvice鎺ュ彛銆?/SPAN>

public interface MethodBeforeAdvice extends BeforeAdvice {

    void before(Method m, Object[] args, Object target) throws Throwable;

}

3銆?SPAN style="FONT: 7pt 'Times New Roman'">  after advice錛氬湪jointcut鎵ц涔嬪悗錛岃繍琛?/SPAN>advice銆傚繀欏誨疄鐜?/SPAN>AfterReturningAdvice鎺ュ彛銆?/SPAN>

public interface AfterReturningAdvice extends Advice {

    void afterReturning(Object returnValue, Method m, Object[] args, Object target)

            throws Throwable;

}

4銆?SPAN style="FONT: 7pt 'Times New Roman'">  throws advice錛氬湪jointcut鎵ц鍑虹幇寮傚父鐨勬椂鍊欙紝榪愯姝?/SPAN>advice銆傚繀欏誨疄鐜?/SPAN>ThrowsAdvice鎺ュ彛銆備絾鏄鎺ュ彛鍙槸涓涓爣璇嗘帴鍙o紝蹇呴』瀹炵幇姝ゅ瀹炵幇涓嬮潰鐨勬柟娉曪細 

afterThrowing([Method], [args], [target], subclassOfThrowable)

   姝ゅ錛屽湪jointcut鍑虹幇寮傚父鏃訛紝鍏蜂綋璋冪敤鍝釜afterThrowing鏂規硶錛岃繖灝辨秹鍙婂埌綾誨瀷鍒ゅ埆錛屾渶絎﹀悎綾誨瀷鍒ゅ埆鐨勫皢浼氳璋冪敤銆?/SPAN>

]]>
Spring AOP 姒傚康http://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1611.htmljinfeng_wangjinfeng_wangWed, 02 Mar 2005 09:30:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1611.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1611.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1611.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1611.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1611.html鍒囬潰錛?/SPAN>Aspect錛夛細瀵硅薄鎿嶄綔榪囩▼涓殑鎴潰錛屼篃灝辨槸鏌愭柟闈㈢殑浠誨姟錛屼緥濡備簨鍔°佹棩蹇椼?/SPAN>

榪炴帴鐐癸紙JoinPoint錛夛細紼嬪簭榪愯榪囩▼涓殑鏌愪釜闃舵鐐廣傚鏌愪釜鏂規硶璋冪敤錛屾垨鑰呮煇涓紓甯歌鎶涘嚭銆?/SPAN>

澶勭悊閫昏緫錛?/SPAN>Advice錛夛細鍦ㄦ煇涓繛鎺ョ偣鎵閲囩敤鐨勫鐞嗛昏緫銆傚鐞嗛昏緫鐨勮皟鐢ㄦā寮忛氬父鏈変笁縐嶏細

i.        Around錛氬湪榪炴帴鐐瑰墠鍚庢彃鍏ラ澶勭悊榪囩▼鍜屽悗澶勭悊榪囩▼銆?/SPAN>

ii.       Before錛氫粎鍦ㄨ繛鎺ョ偣涔嬪墠鎻掑叆棰勫鐞嗚繃紼嬨?/SPAN>

iii.     After錛氬湪榪炴帴鐐逛箣鍚庤繘琛屽鐞嗐?/SPAN>

iv.    Throw錛氬湪榪炴帴鐐規姏鍑哄紓甯告椂榪涜寮傚父澶勭悊銆?/SPAN>

鍒囩偣錛?/SPAN>PointCut錛夛細涓緋誨垪榪炴帴鐐圭殑闆嗗悎錛屽畠鎸囨槑澶勭悊鏂瑰紡錛?/SPAN>Advice錛夊皢鍦ㄤ綍澶勮瑙﹀彂錛屽彲浠ヤ嬌鐢ㄦ鍒欒〃杈懼紡琛ㄨ揪銆?/SPAN>

Advisor錛氭槸PointCut鍜?/SPAN>Advice鐨勭患鍚堜綋錛屽畬鏁存弿榪頒簡涓涓?/SPAN>advice灝嗕細鍦?/SPAN>pointcut鎵瀹氫箟鐨勪綅緗瑙﹀彂銆?/SPAN>

Introduction錛氫負advised object鍔犱笂涓瀹氱殑鏂規硶鎴栬呮暟鎹垚鍛樸備笌Advice灞炰簬騫跺垪鐨勬蹇碉紝浣嗘湁鐫涓瀹氱殑鍖哄埆銆?/SPAN>Advice鍙槸緇?/SPAN>target闄勫姞涓婂叾浠栫殑鍔熻兘錛屼嬌鐢ㄨ呯敋鑷沖彲浠ヨ瀵熶笉鍒幫紝浣嗘槸Introduction鍒欐坊鍔犱簡鍏朵粬鐨勫姛鑳斤紝渚嬪緇?/SPAN>target璧嬩簣浜?/SPAN>lock鍔熻兘錛岀姸鎬佺瓑銆?/SPAN>

]]>
Spring鐨勯厤緗枃浠?/title><link>http://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1603.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Wed, 02 Mar 2005 03:48:00 GMT</pubDate><guid>http://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1603.html</guid><wfw:comment>http://www.tkk7.com/jinfeng_wang/comments/1603.html</wfw:comment><comments>http://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1603.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/jinfeng_wang/comments/commentRss/1603.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/jinfeng_wang/services/trackbacks/1603.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>Spring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勯厤緗枃浠?/SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">1銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">瀵逛簬閭d簺浣跨敤鍒版湁闄愬閮ㄨ祫婧愮殑</SPAN><SPAN lang=EN-US>bean</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屾棤闈炲繀瑕侊紝璇峰敖閲忎嬌鍏?/SPAN><SPAN lang=EN-US>singleton</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>2銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">init-method</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-font-kerning: 0pt">鍦?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">Bean</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-font-kerning: 0pt">鍒涘緩寮濮嬫椂璋冪敤錛?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">destory-method</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-font-kerning: 0pt">鍦ㄩ攢姣佹椂璋冪敤</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">.Spring</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-font-kerning: 0pt">鑷繁鎻愪緵浜?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">InitializingBean</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-font-kerning: 0pt">錛?/SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">DisposableBean</SPAN><SPAN lang=EN-US style="FONT-FAMILY: NewBaskervilleITCbyBT-Roman; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">.</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: NewBaskervilleITCbyBT-Roman; mso-hansi-font-family: NewBaskervilleITCbyBT-Roman; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">榪欎袱涓帴鍙e畬鎴愯繖涓や釜鍔熻兘錛屼竴</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鏃?/SPAN><SPAN lang=EN-US>Bean</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">瀵硅薄瀹炵幇浜嗚繖涓や釜鎺ュ彛錛屽垯鏃犻渶榪涜浠諱綍閰嶇疆錛屽鍣ㄥ氨浼氬疄鐜拌繖涓や釜鍔熻兘銆傦紙褰撶劧錛岃繖涔熷氨浣垮緱浣犵殑搴旂敤鍜?/SPAN><SPAN lang=EN-US>Spring API</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鎹嗙粦鍒頒簡涓璧鳳級</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>3銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN lang=EN-US>Innner Bean</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛氳繖鏍風殑閰嶇疆浣垮緱</SPAN><SPAN lang=EN-US>inner bean</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍙兘琚?/SPAN><SPAN lang=EN-US>wrapper bean</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鎵寮曠敤銆傝繖鐐瑰湪</SPAN><SPAN lang=EN-US>AOP</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">涓挨鍏舵湁鐢細</SPAN><SPAN lang=EN-US>BeanFactory</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍙兘璁塊棶</SPAN><SPAN lang=EN-US>AOProxy</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛岃屼笉鑳界洿鎺ュ緱鍒?/SPAN><SPAN lang=EN-US>AOProxy</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鎵灝佽鐨?/SPAN><SPAN lang=EN-US>target object</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆?/SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>4銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">闆嗗悎鍏冪礌</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align=center><SPAN lang=EN-US><list> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">脿</SPAN></SPAN><SPAN lang=EN-US>java.awt.List, arrays</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align=center><SPAN lang=EN-US><set> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">脿</SPAN></SPAN><SPAN lang=EN-US>java.awt.Set</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align=center><SPAN lang=EN-US><map> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">脿</SPAN></SPAN><SPAN lang=EN-US>java.awt.Map</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-layout-grid-align: none" align=center><SPAN lang=EN-US><props> </SPAN><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">脿</SPAN></SPAN><SPAN lang=EN-US>java.awt.Properties</SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>5銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璁劇疆絀哄鹼細</SPAN><SPAN lang=EN-US><property name="foo"><null/><property></SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>6銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鏋勯犲嚱鏁版敞鍏ワ細鐢ㄤ簬閭d簺蹇呴』鐨勩?/SPAN><SPAN lang=EN-US>final</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勫弬鏁般傚鏋滄瀯閫犲嚱鏁扮殑鍙傛暟鍙兘寮曡搗鍐茬獊錛屽彲浠ュ湪閰嶇疆鏂囦歡涓粰鍚勫弬鏁板姞涓?/SPAN><SPAN lang=EN-US>type</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆?/SPAN></P> <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo5; tab-stops: list 18.0pt; mso-layout-grid-align: none"><SPAN lang=EN-US>7銆?SPAN style="FONT: 7pt 'Times New Roman'">  </SPAN></SPAN><SPAN lang=EN-US>autowiring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛氬畠浼氬甫鏉ヤ竴瀹氱殑闂錛屽洜涓烘棤璁哄浣?/SPAN><SPAN lang=EN-US>autowiring</SPAN><SPAN style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛岄兘鏃犳硶淇濊瘉鍏剁粨鏋滀竴瀹氭紜紝寰堝彲鑳戒細鍑虹幇璁稿涓庨鏈熶笉涓鑷寸殑鍦版柟銆?/SPAN></P><img src ="http://www.tkk7.com/jinfeng_wang/aggbug/1603.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-03-02 11:48 <a href="http://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1603.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Spring涓瑿ontainer綆$悊Beanhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1602.htmljinfeng_wangjinfeng_wangWed, 02 Mar 2005 02:36:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1602.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1602.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/02/1602.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1602.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1602.html鍦?/SPAN>Spring涓紝鍚湁涓や釜閲嶈鐨?/SPAN>Container錛岀敤浜庣鐞嗚繖浜?/SPAN>javabean浠栦滑鏄?/SPAN>BeanFactory鍜?/SPAN>ApplicationContext銆傚叾涓?/SPAN>ApplicationContext緇ф壙浜?/SPAN>BeanFactory鐨勬墍鏈夊姛鑳斤紝榪樻彁渚涗簡i18n銆佺粺涓杞藉叆璧勬簮銆佷簨浠跺垎鍙戠瓑鍔熻兘銆?/SPAN>

鍦?/SPAN>BeanFactory涓紝鎵鏈夌殑bean瀵硅薄鐨勫垱寤洪兘鏄?/SPAN>lazy鐨勶紝鍖呮嫭閭d簺singleton bean銆傚彧鏈?/SPAN>javabean瀵硅薄蹇呴』琚嬌鐢ㄧ殑鏃跺欙紝鎵嶄細鍒涘緩璇ュ璞★紝鎵嶄細姝e紡鐨勮В鏋愮浉搴旂殑xml鏍囪錛岃В鏋愯bean鐨?/SPAN>property絳夈備絾鏄湪ApplicationContext錛屽畠鍙互棰勫厛杞藉叆sigleton bean錛岃屼笉鏄洿鍒頒嬌鐢ㄦ椂鎵嶅垱寤恒?/SPAN>

 

BeanFactory鏈甯哥敤鐨勫疄鐜版槸XmlBeanFactory錛岃澆鍏モ滃畾浣?/SPAN>xml鈥濇枃浠訛細

BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));

 

ApplicationContext鏈変笁縐嶅疄鐜幫細ClassPathXmlApplicationContext錛?/SPAN>FileSystemXmlApplicationContext錛?/SPAN>XmlWebApplicationContext銆傚叾涓墠涓よ呬篃鏄熀浜庤礬寰勭殑錛屽拰BeanFactory鐨?/SPAN>xml鏂囦歡瀹氫綅鏂瑰紡涓鑷淬?/SPAN>

ApplicationContext context =new FileSystemXmlApplicationContext("c:/foo.xml");

ApplicationContext context = new ClassPathXmlApplicationContext("foo.xml");

 

BeanFactory綆$悊Bean瀵硅薄鐨勭敓鍛藉懆鏈燂細

1銆?SPAN style="FONT: 7pt 'Times New Roman'">  浣跨敤鏋勯犲嚱鏁板垱寤?/SPAN>Bean瀵硅薄

2銆?SPAN style="FONT: 7pt 'Times New Roman'">  Bean瀵硅薄autowire琚墽琛?/SPAN>

3銆?SPAN style="FONT: 7pt 'Times New Roman'">  Bean瀵硅薄璋冪敤鍚勯」setXXX鏂規硶

4銆?SPAN style="FONT: 7pt 'Times New Roman'">  濡傛灉璇?/SPAN>Bean瀹炵幇浜?/SPAN>BeanNameAware鎺ュ彛錛屽垯璋冪敤璇ュ璞$殑setBeanName()鏂規硶錛岃緗叾ID錛堝凡緇忓湪xml閰嶇疆鏂囦歡涓啓濂戒簡錛?/SPAN>

5銆?SPAN style="FONT: 7pt 'Times New Roman'">  濡傛灉璇?/SPAN>Bean瀹炵幇浜?/SPAN>BeanFactoryAware鎺ュ彛錛屽垯璋冪敤璇ュ璞$殑setBeanFactory()鏂規硶錛屼紶鍏?/SPAN>BeanFactory瀵硅薄鑷韓

6銆?SPAN style="FONT: 7pt 'Times New Roman'">  濡傛灉宸茬粡閰嶇疆浜?/SPAN>BeanPostProcessor錛岄偅涔堣皟鐢?/SPAN>BeanPostProcessors鐨?/SPAN>pre-

ProcessBeforeInitialization()鏂規硶錛屽璇ean瀵硅薄榪涜澶勭悊錛?/SPAN>

7銆?SPAN style="FONT: 7pt 'Times New Roman'">  濡傛灉璇?/SPAN>bean鑷畾涔変簡init()鏂規硶錛岄偅涔堣皟鐢ㄦ鏂規硶

8銆?SPAN style="FONT: 7pt 'Times New Roman'"> 濡傛灉宸茬粡閰嶇疆浜?/SPAN>BeanPostProcessor錛岄偅涔堣皟鐢ㄨBeanPostProcessors鐨?/SPAN>post

ProcessBeforeInitialization()鏂規硶錛屽璇ean瀵硅薄榪涜澶勭悊

9銆?SPAN style="FONT: 7pt 'Times New Roman'">  姝e父浣跨敤

10銆?SPAN style="FONT: 7pt 'Times New Roman'">              緋葷粺閿姣侊紝濡傛灉璇?/SPAN>bean瀵硅薄瀹炵幇浜?/SPAN>DisposableBean鎺ュ彛錛屽垯璋冪敤鍏?/SPAN>destory()鏂規硶錛?/SPAN>

11銆?SPAN style="FONT: 7pt 'Times New Roman'">              鏈鍚庤皟鐢ㄧ敤鎴峰湪閰嶇疆鏂囦歡涓紪鍐欑殑destroy-method

 



]]>
Sping Live絎旇涓http://www.tkk7.com/jinfeng_wang/archive/2005/03/01/1595.htmljinfeng_wangjinfeng_wangTue, 01 Mar 2005 09:39:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/03/01/1595.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1595.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/03/01/1595.html#Feedback2http://www.tkk7.com/jinfeng_wang/comments/commentRss/1595.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1595.html 

 

鏁翠釜Web搴旂敤鍒嗕負鍥涢儴鍒?/SPAN>

1銆?SPAN style="FONT: 7pt 'Times New Roman'">  鍗曠嫭鐨?/SPAN>DAO錛岃礋璐f暟鎹闂紝鎵цCUID(create, update, insert ,delete)錛?SPAN style="COLOR: red">瀹屾垚O/R鏄犲皠銆備笉娑夊強浠諱綍鐨勫叾浠栭昏緫錛屼粎鎵ц榪欎互涓婄殑鎿嶄綔錛屽鏋滄湁鍞竴鎬ф鏌ャ佷簨鍔′篃涓嶉渶瑕佸仛銆傦紙鍙互鍦ㄦ暟鎹簱绔姞涓浜?/SPAN>trigger,constraint錛夈?SPAN style="COLOR: red">璇ュ眰闇瑕佸畾涔?/SPAN>DAO鎺ュ彛錛?/SPAN>DAO瀹炵幇(hibernate錛?/SPAN>ibaits錛?/SPAN>JDBC絳?/SPAN>)銆?/SPAN>

2銆?SPAN style="FONT: 7pt 'Times New Roman'">  綆鍗曠殑Logic Object錛?/SPAN>Java Bean錛夛紝data field+setter+getter+Other Logic錛屽彲浠ュ皢涓浜涘叡鏈夌殑鎿嶄綔鎻愬彇鍒扮埗綾諱腑錛屽噺灝戜唬鐮併?/SPAN>

3銆?SPAN style="FONT: 7pt 'Times New Roman'">  Business Sevice錛屽疄鐜頒笟鍔¢昏緫錛屽湪姝や嬌鐢?/SPAN>DAO鍜?/SPAN>Logic Object瀹屾垚涓氬姟鎿嶄綔銆?/SPAN>榪欓噷褰撲嬌鐢ㄥ埌DAO鏃訛紝鍙渶瑕?/SPAN>IOC娉ㄥ叆錛岀湡瀹炲璞$敱澶栫晫錛?/SPAN>Web瀹瑰櫒璋冪敤Spring瀹瑰櫒錛夋敞鍏ャ?/SPAN>

4銆?SPAN style="FONT: 7pt 'Times New Roman'">  緙栧啓Action錛屽皢鐢ㄦ埛鐣岄潰鐨勬搷浣滄槧灝勫埌Busibess service銆?/SPAN>

 

浣跨敤Spring MVC鐨勫叿浣撻厤緗細

1銆?/SPAN>鍦?/SPAN>web.xml涓?/SPAN>, 澧炲姞dispatcher鐨勫畾涔夛紝閰嶇疆濂?/SPAN>URL Mapping鍒嗗彂鐢ㄦ埛璋冪敤銆?/SPAN>

        <servlet>

           <servlet-name>action</servlet-name>

        <servlet-class>

org.springframework.web.servlet.DispatcherServlet

</servlet-class>

        <load-on-startup>1</load-on-startup>

        </servlet>

 

    <servlet-mapping>

            <servlet-name>action</servlet-name>

            <url-pattern>*.html</url-pattern>

    </servlet-mapping>

緙栧啓鐩稿簲鐨?/SPAN>action-servlet.xml

 

 

2銆佸鏋滀嬌鐢ㄤ簡澶氫釜context鏂囦歡錛?/SPAN>Spring鐨勯厤緗枃浠訛級錛屽垯闇瑕佸湪Web.xml涓繘琛岄厤緗紝鍏蜂綋濡備笅錛?/SPAN>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

/WEB-INF/applicationContext1.xml

/WEB-INF/applicationContext2.xml

</param-value>

</context-param>

   鍏朵綅緗湪鈥?/SPAN>sitemesh filter鈥濅箣鍚庯紝浣嗘槸鍦?/SPAN>filter-mapping涔嬪墠銆?/SPAN>

 

3. 澧炲姞ContextLoaderListener.

       <listener>

          <listener-class>

org.springframework.web.context.ContextLoaderListener

</listener-class>

  </listener>

 

瀵圭収浜哠pring in action,閭d釜璁茬殑鏇村ソ鍝︺備粠spring鐨勫熀紜寮濮嬭璧鳳紝寰堜笉閿欍?/P>

jinfeng_wang 2005-03-01 17:39 鍙戣〃璇勮
]]>
Spring鍒╃敤dynamic proxy瀹炵幇AOPhttp://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1378.htmljinfeng_wangjinfeng_wangSun, 20 Feb 2005 14:17:00 GMThttp://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1378.htmlhttp://www.tkk7.com/jinfeng_wang/comments/1378.htmlhttp://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1378.html#Feedback0http://www.tkk7.com/jinfeng_wang/comments/commentRss/1378.htmlhttp://www.tkk7.com/jinfeng_wang/services/trackbacks/1378.html鑷充簬涓婇潰鎵璇寸殑鍔ㄦ佷唬鐞嗭紝緇欎綘涓涓洿綆鍗曠殑璇存硶錛屾瘮濡係pring閲岀殑TransactionProxyFactoryBean錛屼粬鏄鏀寔浜嬪姟綆$悊鐨勪竴涓唬鐞咶actoryBean錛屽埄鐢ㄥ姩鎬佷唬鐞嗭紝榪欎釜綾誨彲浠ヤ笉渚濊禆浜庡叿浣撶殑target 鎺ュ彛錛岀敤鎴峰彲浠ラ殢鎰忛夋嫨target 鎺ュ彛銆備篃涓嶉渶瑕佺敤鎴峰啀鎵嬪伐鏍規嵁鑷繁鐨則arget 鎺ュ彛鎵╁睍涓涓猅ransactionProxyFactoryBean銆?榪欐牱鐨勪竴涓敤鍒癹ava.lang.reflect鐨勫姩鎬佷唬鐞嗘満鍒訛紝浣垮緱鐢ㄦ埛闇瑕佺紪鍐欑殑浠g爜閲忓ぇ澶у噺灝忥紝涔熶嬌寰楁暣涓鏋墮厤緗嬌鐢ㄨ秼浜庝竴鑷淬俒/quote]


java浠g爜: 

        <bean id="someObjectProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">   
                 <value>ISomeInterface</value> 
                </property>       
                <property name="target">           
                        <ref bean="someObject"/>       
                </property>       
                <property name="interceptorNames">           
                        <list>               
                                <value>lockMixinAdvisor</value>           
                    </list>       
                </property>   
        </bean>




鎴戝鎬殑鏄紝鏃㈢劧鏈変笅闈㈣繖涓紝
java浠g爜: 


<bean id="someObjectProxy" class="org.springframework.aop.framework.ProxyFactoryBean">



閭d箞紼嬪簭浠g爜涓紝 鎬庝箞鍙互榪欐牱鍐欙紵
java浠g爜: 


ISomeInterface someObjectProxy = (ISomeInterface) context
                .getBean("someObjectProxy");


娉ㄦ剰錛岃繖閲岃繑鍥炵殑鏄疘SomeInterface 錛岃屼笖榪欎釜someObjectProxy 瀵硅薄宸茬粡鍏鋒湁浜咺Lock錛婭SomeInterface 鐨勫姛鑳斤紝騫朵笖鍦ㄨ涓鴻〃鐜扮殑瀹屽叏鍜孖SomeInterface 涓鑷淬?

濡傛灉Spring鐨勪唬鐮佹槸棰勭紪璇戠殑錛岄偅鍙互浜х敓stub涔嬬被鐨勶紝鍙繖閲屾槸鎬庝箞瀹炵幇鐨勶紝鎸鴻浜哄鎬摝錛岃皝鑳借В閲婁竴涓嬩箞錛?

絳旀 錛?http://www.javajia.com/article.php?id=919


鍙槸鍦ㄨ繖涓婇潰鍐嶅皝瑁呯殑瀹岀編緗簡錛屽ソ濂界爺絀禿ynamic proxy鐨勫疄鐜板惂銆?/P>


姝ゅ錛岃繕鏈夎繖涓孌靛摝 錛氾級

AOP鐨勪綔鐢ㄥ彲浠ョ畝鍗曞涓嬫墍璇達細鈥滃湪涓涓粍浠剁殑鍓嶅悗鍔犱笂涓浜涘浐瀹氱殑鍐呭銆傗?鎶涘紑AOP涓嶈錛屾垜浠嚜宸卞鏋滄兂瑕佸啓榪欎笢瑗匡紝鏃犻潪涓ょ鏂瑰紡錛屼竴涓槸proxy瀹炵幇錛岀劧鍚庡湪proxy鐨勫墠鍚庢坊鍔犲唴瀹癸紱榪樻湁涓縐嶅氨鏄痶emplate瀹炵幇銆?
鎵浠ュ湪鎴戠湅鏉ワ紝鏁版嵁搴撳眰鐨勬ā鏉垮叾瀹炰篃綆楁槸涓縐嶁淎OP鈥濄?涓嶇煡閬撴湁娌′漢瀵規鏈変簺鎰忚鍜岃瘎榪幫紵



jinfeng_wang 2005-02-20 22:17 鍙戣〃璇勮
]]>
Spring IDE鐨勪嬌鐢?/title><link>http://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1372.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Sun, 20 Feb 2005 08:25:00 GMT</pubDate><guid>http://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1372.html</guid><wfw:comment>http://www.tkk7.com/jinfeng_wang/comments/1372.html</wfw:comment><comments>http://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1372.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/jinfeng_wang/comments/commentRss/1372.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/jinfeng_wang/services/trackbacks/1372.html</trackback:ping><description><![CDATA[<P>涓嬭澆浜唖pring ide, 鍏跺叿浣撶殑浣跨敤鏂規硶銆?/P> <H2>Usage </H2> <H2><A name=usage-fresh></A>Fresh Installation</H2> <OL> <LI>Add Spring Beans project nature <UL> <LI>select open project nodes in Eclipse resource navigator錛?or JDT package explorer <LI> 鍦‥clipse鐨剅esource navigator紿楀彛涓墦寮欏圭洰錛岋紙鎴栬呭湪 JDT package explorer紿楀彛錛? <LI>activate context menu item "Add Spring Beans Project Nature" on selected projects -> these projects are now decorated with a small 'S' in the upper right corner (overwriting other decorators, e.g. Java project decorator 'J')  <LI>鍦ㄦ墍鎵撳紑鐨勯」鐩腑錛屽彸閿」鐩悕錛岄夋嫨鈥淎dd Spring Beans Project Nature鈥濓紝榪欐椂璇ラ」鐩氨浼氬湪鍙充笂瑙掓寕涓婁簡鈥淪鈥? :) </LI></UL> <LI>Add references to other Spring projects <UL> <LI>open project's properties dialog in Eclipse resource navigator or JDT package explorer  <LI> 鍙抽敭欏圭洰鍚嶏紝鏌ョ湅鍏秔roperties,榪欏氨鎵撳紑浜?project properties"紿楀彛 <LI>select the properties page "Project References" from the list  <LI> 榪欐椂灝卞彲浠ラ夋嫨 "Project References"</LI></UL> <UL> <LI>select Spring project(s) containing Spring Beans config files which are referenced from within in this project's Spring Beans config sets  <LI>閫夋嫨 鎵渚濊禆寮曠敤鐨勯」鐩?/LI></UL> <LI>Add Spring Beans factory config files <UL> <LI>open project's properties dialog in Eclipse resource navigator or JDT package explorer or via double-clicking a project in the Spring Beans view <LI>鍚屾牱錛屽啀嬈℃墦寮欏圭洰鐨勫睘鎬у璇濇錛屾垨鑰呬篃鍙互鎵撳紑鈥淪pring Beans View鈥?榪欎釜紿楀彛鍙互鍦╳indow->slow view閲岄潰鎵撳紑) <LI>select the properties page "Spring Beans Project" from the list <LI>鍦ㄩ」鐩殑灞炴х獥鍙d腑閫夋嫨"Spring Beans Project" <LI>use button "Add..." to open a selector dialog and select all Spring Beans config files -> added Spring Beans config files are decorated with a small 'S' in the upper right corner <LI>閫氳繃鈥淎dd鈥濇寜閽夋嫨Spring閰嶇疆鏂囦歡銆? <LI>(optionally) combine config files into config sets with the second tab of the property page (use "New..." to create a new config set and select the config files; use "Move Up" and "Move Down" to change the order of the config files) </LI></UL> <LI>Open Spring Beans view <UL> <LI>select from within any of the added Spring Beans config files opened in an Eclipse editor the menu item "Navigate/Show In/Spring Beans" -> Spring Beans view is opened and the corresponding Spring Beans config file is selected in the view's model <LI> Double clicking on an entry in the view navigates to the corresponding location in the config file </LI></UL> <LI>Validate Spring Beans config file <UL> <LI>save any of the added Spring Beans config files from within an open Eclipse editor -> all errors occured during validation create a problem marker in Eclipse's task view <LI>淇濆瓨Spring閰嶇疆鏂囦歡錛岃繖鏃跺氨鍙互鐪嬪埌閿欒浜?錛堜亢娌℃湁鑳藉鍦╰ask紿楀彛涓湅鍒幫紝浣嗗湪Bean.xml鏂囦歡鐨勭紪杈戠獥鍙g湅鍒頒簡錛屽樆鍢伙綖锝烇綖錛? <LI>鍙﹀錛屽彲浠ヨ瀵熶竴涓?Spring beans"閭d釜紿楀彛錛屽湪鍏朵笂闈㈡湁涓変釜鎸夐挳錛岀涓変釜鏄?show in property sheet", 榪欎釜鍔熻兘涓嶉敊鍝︼紝鍙互璇曚竴涓嬨傚綋鐒朵簡錛岀洿鎺ョ湅xml鏂囦歡涔熸槸鎸哄ソ鐨勩?/LI></UL></LI></OL> <P>6銆侀潪甯稿ソ鐨勪竴涓姛鑳斤紝鍦⊿pring Beans閭d釜紿楀彛涓坊鍔犲ソ浣犵殑Spring閰嶇疆鏂囦歡涔嬪悗錛屽湪鍏朵腑鍙抽敭浣犵殑閰嶇疆鏂囦歡錛岄夋嫨鈥渟how graph鈥濓紝it's such a wonderful function~~~~</P> <P>鍦ㄧ嚎瀹夎鍦板潃錛? <A >http://springframework.sourceforge.net/spring-ide/eclipse/updatesite/</A>.  </P> <P>娉ㄦ剰鍝︼紝鍦ㄥ畨瑁呯殑鏃跺欙紝涓瀹氳閫夆淪pring framework鈥?鐒跺悗鎵嶅彲浠ヨ鈥淪pring IDE鈥?灝辨槸Beans Configuration Support鍟︺?</P> <P> </P><img src ="http://www.tkk7.com/jinfeng_wang/aggbug/1372.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-02-20 16:25 <a href="http://www.tkk7.com/jinfeng_wang/archive/2005/02/20/1372.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://8654123.com" target="_blank">免费一级毛片在线播放不收费</a>| <a href="http://kwknc.com" target="_blank">亚洲国产精品久久久久网站</a>| <a href="http://www-44455588.com" target="_blank">国产精品免费看久久久香蕉</a>| <a href="http://lijieedu.com" target="_blank">亚洲国产精品成人精品无码区</a>| <a href="http://bx85.com" target="_blank">亚洲国产精品免费在线观看</a>| <a href="http://5d8f.com" target="_blank">国产AV无码专区亚洲AV琪琪</a>| <a href="http://okbala.com" target="_blank">亚洲国产精品高清久久久</a>| <a href="http://c7vl.com" target="_blank">最近的中文字幕大全免费版</a>| <a href="http://hh5151.com" target="_blank">精品一区二区三区高清免费观看</a>| <a href="http://625r.com" target="_blank">亚洲中文字幕人成乱码</a>| <a href="http://xjscr.com" target="_blank">亚洲精品乱码久久久久久不卡</a>| <a href="http://45-po.com" target="_blank">啦啦啦完整版免费视频在线观看 </a>| <a href="http://qnyjny.com" target="_blank">国产亚洲综合久久</a>| <a href="http://hberay.com" target="_blank">黑人精品videos亚洲人</a>| <a href="http://173ba.com" target="_blank">在线a毛片免费视频观看</a>| <a href="http://gwcyy.com" target="_blank">99视频在线观看免费</a>| <a href="http://8833081.com" target="_blank">亚洲国产精品网站在线播放</a>| <a href="http://uu313.com" target="_blank">无码专区—VA亚洲V天堂</a>| <a href="http://ddhlj.com" target="_blank">亚洲VA综合VA国产产VA中</a>| <a href="http://116com.com" target="_blank">三年片在线观看免费大全</a>| <a href="http://456jjj.com" target="_blank">国产啪精品视频网站免费尤物</a>| <a href="http://lh726.com" target="_blank">亚洲国产成人久久精品大牛影视</a>| <a href="http://1111xxxx.com" target="_blank">亚洲色图在线观看</a>| <a href="http://minliusoft.com" target="_blank">亚洲国产成人久久综合野外</a>| <a href="http://78avai.com" target="_blank">欧美三级在线电影免费</a>| <a href="http://avqvod.com" target="_blank">亚洲a一级免费视频</a>| <a href="http://badabg.com" target="_blank">一本久久A久久免费精品不卡</a>| <a href="http://147v.com" target="_blank">亚洲午夜一区二区三区</a>| <a href="http://cnepu.com" target="_blank">久久亚洲美女精品国产精品</a>| <a href="http://123994.com" target="_blank">亚洲日韩国产成网在线观看</a>| <a href="http://35xyz.com" target="_blank">最新中文字幕电影免费观看</a>| <a href="http://www-yhty.com" target="_blank">日本免费人成视频在线观看</a>| <a href="http://www-533999.com" target="_blank">亚洲国产免费综合</a>| <a href="http://963315.com" target="_blank">美女黄频视频大全免费的</a>| <a href="http://okgou58.com" target="_blank">亚洲综合激情五月丁香六月</a>| <a href="http://818812.com" target="_blank">在线电影你懂的亚洲</a>| <a href="http://hs969.com" target="_blank">久久夜色精品国产亚洲</a>| <a href="http://ziguang1688.com" target="_blank">亚洲综合激情另类专区</a>| <a href="http://hkschooltv.com" target="_blank">免费永久国产在线视频</a>| <a href="http://wwwly6080.com" target="_blank">免费视频中文字幕</a>| <a href="http://vvbbn.com" target="_blank">无码高潮少妇毛多水多水免费</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>