{"id":1674,"date":"2010-05-06T08:56:16","date_gmt":"2010-05-06T00:56:16","guid":{"rendered":"\/?p=1674"},"modified":"2010-05-06T08:56:16","modified_gmt":"2010-05-06T00:56:16","slug":"1674","status":"publish","type":"post","link":"https:\/\/www.justzz.com\/spec\/1674.html","title":{"rendered":"Struts2+Spring\u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"<p><strong>\\<\/strong>WebRoot\\WEB-INF\\web.xml<br \/>\n(JavaEE5)<\/p>\n<p><strong>&lt;<\/strong>?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<br \/>\n&lt;web-app version=\"2.5\"<br \/>\nxmlns=\"http:\/\/java.sun.com\/xml\/ns\/javaee\"<br \/>\nxmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<br \/>\nxsi:schemaLocation=\"http:\/\/java.sun.com\/xml\/ns\/javaee<br \/>\nhttp:\/\/java.sun.com\/xml\/ns\/javaee\/web-app_2_5.xsd\"&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- Spring2.0 \u914d\u7f6e --&gt;<br \/>\n&lt;listener&gt;<br \/>\n&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- Struts2.1 \u914d\u7f6e --&gt;<br \/>\n&lt;filter&gt;<br \/>\n&lt;filter-name&gt;struts2&lt;\/filter-name&gt;<br \/>\n&lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;\/filter-class&gt;<br \/>\n&lt;\/filter&gt;<br \/>\n&lt;filter-mapping&gt;<br \/>\n&lt;filter-name&gt;struts2&lt;\/filter-name&gt;<br \/>\n&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;<br \/>\n&lt;\/filter-mapping&gt;<\/p>\n<p><strong>&lt;<\/strong>\/web-app&gt;<\/p>\n<p>-------------------------------------------------------------------------------------<\/p>\n<p><strong>\/<\/strong>src\/struts.xml<\/p>\n<p><strong>&lt;<\/strong>?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;<br \/>\n&lt;!DOCTYPE struts PUBLIC<br \/>\n\"-\/\/Apache Software Foundation\/\/DTD Struts Configuration 2.0\/\/EN\"<br \/>\n\"http:\/\/struts.apache.org\/dtds\/struts-2.0.dtd\"&gt;<br \/>\n&lt;struts&gt;<br \/>\n&lt;!-- \u914d\u7f6e\u6d4b\u8bd5action\u00a0 --&gt;<br \/>\n&lt;package name=\"ums\"\u00a0 extends=\"struts-default\"&gt;<br \/>\n&lt;action name=\"login\" class=\"loginAction\"&gt;<br \/>\n&lt;result name=\"success\"&gt;\/login\/welcome.jsp&lt;\/result&gt;<br \/>\n&lt;result name=\"error\"&gt;\/login\/error.jsp&lt;\/result&gt;<br \/>\n&lt;result name=\"input\"&gt;\/login\/login.jsp&lt;\/result&gt;<br \/>\n&lt;\/action&gt;<br \/>\n&lt;\/package&gt;<br \/>\n&lt;\/struts&gt;<\/p>\n<p>-------------------------------------------------------------------------------------<\/p>\n<p><strong>\/<\/strong>WebRoot\/WEB-INF\/applicationContext.xml<\/p>\n<p><strong>&lt;<\/strong>?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<br \/>\n&lt;beans<br \/>\nxmlns=\"http:\/\/www.springframework.org\/schema\/beans\"<br \/>\nxmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<br \/>\nxsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-2.0.xsd\"&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- \u62e6\u622a\u5668 --&gt;<br \/>\n&lt;bean id=\"myAdvice\" class=\"com.reg.advice.BeforeAdvice\"&gt;&lt;\/bean&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- delegate sessionFactory\u00a0 --&gt;<br \/>\n&lt;bean id=\"sessionFactory\"<br \/>\nclass=\"org.springframework.orm.hibernate3.LocalSessionFactoryBean\"&gt;<br \/>\n&lt;property name=\"configLocation\"<br \/>\nvalue=\"classpath:hibernate.cfg.xml\"&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- spring transaction --&gt;<br \/>\n&lt;bean id=\"transactionManager\" class=\"org.springframework.orm.hibernate3.HibernateTransactionManager\"&gt;<br \/>\n&lt;property name=\"sessionFactory\"&gt;<br \/>\n&lt;ref local=\"sessionFactory\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- DAO implement class\u00a0\u00a0\u00a0\u00a0\u00a0 IOC --&gt;<br \/>\n&lt;bean id=\"userDao\" class=\"com.reg.hibernate.dao.UserDao\"&gt;<br \/>\n&lt;property name=\"sessionFactory\"&gt;<br \/>\n&lt;ref local=\"sessionFactory\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;!-- userDAO \u7684 Spring\u4e8b\u7269\u59d4\u6258\u4ee3\u7406 --&gt;<br \/>\n&lt;bean id=\"userDaoProxy\"<br \/>\nclass=\"org.springframework.transaction.interceptor.TransactionProxyFactoryBean\"&gt;<br \/>\n&lt;property name=\"transactionManager\"&gt;<br \/>\n&lt;ref local=\"transactionManager\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;property name=\"target\"&gt;<br \/>\n&lt;ref local=\"userDao\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;property name=\"transactionAttributes\"&gt;<br \/>\n&lt;props&gt;<br \/>\n&lt;prop key=\"save*\"&gt;PROPAGATION_REQUIRED&lt;\/prop&gt;<br \/>\n&lt;!--<br \/>\n&lt;prop key=\"*\"&gt;PROPAGATION_REQUIRED&lt;\/prop&gt;<br \/>\n&lt;prop key=\"get*\"&gt;PROPAGATION_REQUIRED,readOnly&lt;\/prop&gt;<br \/>\n&lt;prop key=\"save*\"&gt;PROPAGATION_REQUIRED &lt;\/prop&gt;<br \/>\n&lt;prop key=\"update*\"&gt;PROPAGATION_REQUIRED &lt;\/prop&gt;<br \/>\n&lt;prop key=\"delete*\"&gt;PROPAGATION_REQUIRED &lt;\/prop&gt;<br \/>\n&lt;prop key=\"find*\"&gt;PROPAGATION_REQUIRED,readOnly &lt;\/prop&gt;<br \/>\n--&gt;<br \/>\n&lt;\/props&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;!-- User\u4e1a\u52a1\u903b\u8f91\u7ec4\u4ef6\u4f9d\u8d56Spring\u5bf9UserDAO\u7684\u4e8b\u7269\u4ee3\u7406\u00a0 Transaction --&gt;<br \/>\n&lt;bean id=\"userService\" class=\"com.reg.service.impl.ServiceImpl\" &gt;<br \/>\n&lt;property name=\"userDao\"&gt;<br \/>\n&lt;ref local=\"userDaoProxy\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- User\u4e1a\u52a1\u903b\u8f91\u7ec4\u4ef6 \u4f9d\u8d56 UserDao --&gt;<br \/>\n&lt;!--<br \/>\n&lt;bean id=\"userService\" class=\"com.reg.service.impl.ServiceImpl\" &gt;<br \/>\n&lt;property name=\"userDao\"&gt;<br \/>\n&lt;ref local=\"userDao\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n--&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- \u5411Action\u6ce8\u5165\u903b\u8f91\u7ec4\u4ef6 --&gt;<br \/>\n&lt;!--<br \/>\n&lt;bean id=\"loginAction\" class=\"com.reg.LoginAction\" scope=\"prototype\"&gt;<br \/>\n&lt;property name=\"us\" ref=\"userService\"&gt;&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n--&gt;<\/p>\n<p><strong>&lt;<\/strong>!-- \u5411Action\u6ce8\u5165\u903b\u8f91\u7ec4\u4ef6 AOP--&gt;<br \/>\n&lt;bean id=\"loginAction\" class=\"com.reg.LoginAction\" scope=\"prototype\"&gt;<br \/>\n&lt;property name=\"us\" ref=\"userServiceAdivsor\"&gt;&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;!-- AOP \u4ea7\u751f\u4ee3\u7406\u5bf9\u8c61 --&gt;<br \/>\n&lt;bean id=\"userServiceAdivsor\" class=\"org.springframework.aop.framework.ProxyFactoryBean\" &gt;<br \/>\n&lt;!-- \u4ee3\u7406\u5bf9\u8c61\u5b9e\u73b0\u7684\u63a5\u53e3 --&gt;<br \/>\n&lt;property name=\"proxyInterfaces\"&gt;<br \/>\n&lt;value&gt;com.reg.service.IService&lt;\/value&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;!-- \u8bbe\u7f6e\u4ee3\u7406\u5bf9\u8c61 --&gt;<br \/>\n&lt;property name=\"target\"&gt;<br \/>\n&lt;ref local=\"userService\"\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;!-- \u4ee3\u7406\u5bf9\u8c61\u4f7f\u7528\u7684\u62e6\u622a\u5668 --&gt;<br \/>\n&lt;property name=\"interceptorNames\"&gt;<br \/>\n&lt;list&gt;<br \/>\n&lt;value&gt;myAdvice&lt;\/value&gt;<br \/>\n&lt;\/list&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<br \/>\n&lt;\/beans&gt;<\/p>\n<p>-------------------------------------------------------------------------------------<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\\WebRoot\\WEB-INF\\web.xml (JavaEE5) &lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; &lt;web-app version=\"2.5\" xmlns=\"http:\/\/java.&hellip;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1674","post","type-post","status-publish","format-standard","hentry","category-t"],"_links":{"self":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/comments?post=1674"}],"version-history":[{"count":0,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1674\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media?parent=1674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/categories?post=1674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/tags?post=1674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}