{"id":987,"date":"2010-10-02T00:26:29","date_gmt":"2010-10-02T00:26:29","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=987"},"modified":"2010-10-02T00:26:29","modified_gmt":"2010-10-02T00:26:29","slug":"spring%e4%b8%8estruts1-x%e7%9a%84%e6%95%b4%e5%90%88","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/02\/spring%e4%b8%8estruts1-x%e7%9a%84%e6%95%b4%e5%90%88\/","title":{"rendered":"Spring\u4e0eStruts1.x\u7684\u6574\u5408"},"content":{"rendered":"<p>1\uff0c\u6dfb\u52a0struts1.x, Spring\u80fd\u529b<\/p>\n<p>2, \u5728struts1.x\u7684\u914d\u7f6e\u6587\u4ef6struts-config.xml\u4e2d\u914d\u7f6e\u4e0eSpring\u7684\u8054\u7cfb<br \/>\n&lt;action-mappings &gt;<br \/>\n&lt;action<br \/>\nattribute=&#8221;loginForm&#8221;<br \/>\ninput=&#8221;\/login.jsp&#8221;<br \/>\nname=&#8221;loginForm&#8221;<br \/>\npath=&#8221;\/login&#8221;?? \/\/\u5728Spring\u7684applicationContext.xml\u4e2d\u8981\u7528\u6b64path\u5f53\u505abean id<br \/>\nscope=&#8221;request&#8221;<br \/>\ntype=&#8221;org.springframework.web.struts.DelegatingActionProxy&#8221; &gt;<br \/>\n?? \/\/\u4ea4\u7531Spring\u6765\u751f\u6210action,\u800c\u4e0d\u662f\u5728\u6b64\u5c31\u6307\u5b9a\u5177\u4f53\u7684\u7c7b<br \/>\n&lt;forward name=&#8221;success&#8221; path=&#8221;\/success.jsp&#8221; \/&gt;<br \/>\n&lt;\/action&gt;<br \/>\n&lt;\/action-mappings&gt;<\/p>\n<p>&lt;message-resources parameter=&#8221;com.yourcompany.struts.ApplicationResources&#8221; \/&gt;<br \/>\n&lt;!&#8211; \u96c6\u6210Spring\u63d2\u4ef6 &#8211;&gt;<br \/>\n&lt;plug-in className=&#8221;org.springframework.web.struts.ContextLoaderPlugIn&#8221;&gt;<br \/>\n&lt;set-property property=&#8221;contextConfigLocation&#8221; value=&#8221;\/WEB-INF\/classes\/applicationContext.xml&#8221;\/&gt;<br \/>\n&lt;\/plug-in&gt;<br \/>\n? \/\/ struts\u6dfb\u52a0Spring\u63d2\u4ef6<br \/>\n\u6ce8:\u4e5f\u53ef\u4e0d\u7528\u63d2\u4ef6, \u5229\u7528\u5982struts 2.0 \u7684\u65b9\u5f0f\u5728web.xml\u4e2d\u914d\u7f6eSpring\u76d1\u542c\u5668 \u5373:<br \/>\n&lt;listener&gt;<br \/>\n&lt;listener-class&gt;<br \/>\norg.springframework.web.context.ContextLoaderListener<br \/>\n&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<\/p>\n<p>&lt;context-param&gt;<br \/>\n&lt;param-name&gt;contextConfigLocation&lt;\/param-name&gt;<br \/>\n&lt;param-value&gt;\/WEB-INF\/classes\/applicationContext.xml&lt;\/param-value&gt;<br \/>\n&lt;\/context-param&gt;<\/p>\n<p>3\uff0c\u5728Spring\u4e2d\u6dfb\u52a0action\u7684\u751f\u6210<br \/>\n&lt;bean name=&#8221;\/login&#8221; scope=&#8221;prototype&#8221; &gt;<br \/>\n&lt;property name=&#8221;myService&#8221;&gt;<br \/>\n??? &lt;ref bean=&#8221;myService&#8221;\/&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<\/p>\n<p>ps: struts 1.x , struts2.0\u4e0eSpring\u6574\u5408\u7684\u533a\u522b\uff1a<br \/>\n\uff081\uff091.x \u662f\u6574\u4e2aaction\u6ce8\u5165\uff0c\u751f\u6210\u7531Spring\u8d1f\u8d23\uff0c\u800c2.0\u8ba9spring\u8d1f\u8d23\u5c5e\u6027\u7684\u6ce8\u5165\uff0c\u4e5f\u53ef\u8d1f\u8d23action\u7684\u521b\u5efa\u3002<br \/>\n\uff082\uff091.x\u4e0eSpring\u7684\u8054\u7cfb\u662f\u5728\u5176\u914d\u7f6e\u6587\u4ef6struts-config.xml\u4e2d\u901a\u8fc7\u63d2\u4ef6\u673a\u5236\u5b8c\u6210\uff0c\u4e5f\u53ef\u5728web.xml\u4e2d\u914d\u7f6eSpring\u8fc7\u6ee4\u5668\u5b8c\u6210.\u90fd\u5e02\u800c2.0\u662f\u5728 web.xml\u4e2d\u901a\u8fc7\u914d\u7f6e\u8fc7\u6ee4\u5668\u6765\u5b8c\u6210\u8fd9\u79cd\u8054\u7cfb\u3002<br \/>\n(3)?? 1.x \u662f\u5168\u90e8\u6ce8\u5165:struts-config.xml\u4e2d\u8981\u914d\u7f6e\u6bcf\u4e2aaction\u4e0espring\u7684\u8054\u7cfb???????????? type=&#8221;org.springframework.web.struts.DelegatingActionProxy&#8221; &gt;<br \/>\n\u7136\u540e\u5728spring\u7684applicationContext.xml\u4e2d\u914d\u7f6e\u5bf9\u5e94\u7684bean<br \/>\n??? 2.0\u4e0d\u4ec5\u6709\u5168\u90e8\u6ce8\u5165,\u8fd8\u6709\u5c5e\u6027\u6ce8\u5165.<br \/>\n???? 2.0 \u5c5e\u6027\u6ce8\u5165\uff0c\u5728struts2.0\u7684struts.xml\u4e2d\u65e0\u987b\u914d\u7f6e\u6bcf\u4e2aaction\u4e0eSpring\u7684\u8054\u7cfb\uff0c\u53ea\u987b\u5728action\u7c7b\u4e2d\u6307\u5b9a\u4e00\u4e2a\u5c5e\u6027\u540d\uff0c\u6b64\u5c5e\u6027\u540d\u4e0eapplication.context.xml\u4e2d\u67d0\u4e00bean id\u76f8\u540c\u5373\u53ef\u3002<br \/>\n???? 2.0 \u6240\u6709\u6ce8\u5165:\u6258\u7ba1action\u7684\u6240\u6709\u751f\u547d\u5468\u671f,\u8981\u5728struts.xml\u4e2d\u4e3aaction\u7684class\u6307\u5b9a\u4e3aSpring\u7684applicationContext.xml\u4e2d\u7684\u4e00\u4e2abean id,\u8fd9\u6837\u5c31\u53ef\u5b8c\u6210\u6240\u6709\u6258\u7ba1.<br \/>\n\u65e0\u8bba\u662f1.x,\u8fd8\u662f2.0\uff0c\u82e5\u60f3\u8ba9spring\u6ce8\u5165\u5c5e\u6027\uff0c\u5fc5\u987b\u5728\u7c7b\u4e2d\u4e3a\u6b64\u5c5e\u6027\u6307\u5b9aset,get\u65b9\u6cd5\uff0c\u800c\u4e0d\u8bba\u6b64\u5c5e\u6027\u662fprivate,\u8fd8\u662fpublic<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u6dfb\u52a0struts1.x, Spring\u80fd\u529b 2, \u5728struts1.x\u7684\u914d\u7f6e\u6587\u4ef6struts-config [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-spring"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}