??xml version="1.0" encoding="utf-8" standalone="yes"?>超碰公开在线,77导航福利在线,中文字幕一区二区三中文字幕http://www.aygfsteel.com/ldwblog/category/41228.html态度军_一?/description>zh-cnTue, 07 Jan 2020 10:49:26 GMTTue, 07 Jan 2020 10:49:26 GMT60个h公众受Java爱好者社区」高质量原创文章持箋输出Q欢q各位小d?/title><link>http://www.aygfsteel.com/ldwblog/archive/2019/10/30/434887.html</link><dc:creator>David1228</dc:creator><author>David1228</author><pubDate>Wed, 30 Oct 2019 06:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/ldwblog/archive/2019/10/30/434887.html</guid><wfw:comment>http://www.aygfsteel.com/ldwblog/comments/434887.html</wfw:comment><comments>http://www.aygfsteel.com/ldwblog/archive/2019/10/30/434887.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ldwblog/comments/commentRss/434887.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ldwblog/services/trackbacks/434887.html</trackback:ping><description><![CDATA[blogjava|站与博客园合ƈ了,对blogjavaq是有感情的?br />q且blogjava|站发布的文章是在博客园首页看不到的?br />blogjava|站首页能看刎ͼ你可以点L题进入可以看到图片二l码信息?br /><br /><strong style="color: red; font-size: 14pt;">Java爱好者社?/strong><br />公众号内容简介:<br /><p><span style="background-color: yellow; color: red;">专注于分享Java后端相关技术、老司机实战干货,不限于JVM、ƈ发、设计模式、性能优化、分布式&微服务、云原生、大数据相关主题?/span><br style="color: red;" /><span style="background-color: yellow; color: red;">希望x的你停下脚步Q定有所收获?/span><br style="color: red;" /><br />以前的个人博客内容不好迁U,所以我打算Ҏ自己的多q经验,不断整理输出有h值的内容?br />目前公众号内Ҏ关于<span style="background-color: yellow; color: red;">SpringCloudQ微服务框架Q、SkywalkingQAPM监控调用链)、JVMQGC分析、内存泄漏分析)、ƈ发编E?/span>相关原创实战文章已出炉?br /><br />最q刚开始已l有不少伙伴关注了Q期待能有幸搜烦到本博客的同学,可以扫码x一下,不胜感激?br />大家有Q何技术、职场、面试上的问题都可以与我交流?br /><br /><span style="background-color: yellow;"><strong>方式一Q?/strong></span><span style="color: red; background-color: yellow;"><strong>扫码以下公众号二l码Q?/strong></span><br /><img src="http://www.aygfsteel.com/images/blogjava_net/ldwblog/Java%E7%88%B1%E5%A5%BD%E8%80%85%E7%A4%BE%E5%8C%BA%E4%BA%8C%E7%BB%B4%E7%A0%81.png" border="0" alt="" /><br /><br />方式二:<span style="color: red;">在微信上直接搜烦Q?nbsp;</span><span style="color: red; background-color: yellow;">javatech_cbo</span><br /><br />感谢各位伙伴的支持Q后l会在该公众号上输出大量的有价值的实战q货 Q期待与你一同进步与成长?br /></p><img src ="http://www.aygfsteel.com/ldwblog/aggbug/434887.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ldwblog/" target="_blank">David1228</a> 2019-10-30 14:10 <a href="http://www.aygfsteel.com/ldwblog/archive/2019/10/30/434887.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mybatis3.2.1整合Spring3.1http://www.aygfsteel.com/ldwblog/archive/2013/07/10/401418.htmlDavid1228David1228Wed, 10 Jul 2013 10:07:00 GMThttp://www.aygfsteel.com/ldwblog/archive/2013/07/10/401418.htmlhttp://www.aygfsteel.com/ldwblog/comments/401418.htmlhttp://www.aygfsteel.com/ldwblog/archive/2013/07/10/401418.html#Feedback2http://www.aygfsteel.com/ldwblog/comments/commentRss/401418.htmlhttp://www.aygfsteel.com/ldwblog/services/trackbacks/401418.html阅读全文

David1228 2013-07-10 18:07 发表评论
]]>
Spring 3.2三个值得x的新Ҏ?/title><link>http://www.aygfsteel.com/ldwblog/archive/2013/07/10/401397.html</link><dc:creator>David1228</dc:creator><author>David1228</author><pubDate>Wed, 10 Jul 2013 03:48:00 GMT</pubDate><guid>http://www.aygfsteel.com/ldwblog/archive/2013/07/10/401397.html</guid><wfw:comment>http://www.aygfsteel.com/ldwblog/comments/401397.html</wfw:comment><comments>http://www.aygfsteel.com/ldwblog/archive/2013/07/10/401397.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ldwblog/comments/commentRss/401397.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ldwblog/services/trackbacks/401397.html</trackback:ping><description><![CDATA[<p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;">不得不承认的?在目前的web应用开发中,Spring的应用越来越q泛,其地位变得相当重要。而在最q推出的Spring 3.2版本中,又引入了一些新的值得x的特性。本文中介l其中一些值得x的新Ҏ?/p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><strong>一 不再需要web.xml</strong></p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><strong> </strong>在新的Spring 3.2中,可以不再需要web.xmlq个文g了,q得益于Servlet 3.0的新Ҏ?/p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;">其中Q可以用@WebServlet在需要调用的servlet中,使用注解去设|servlet中的映射关系。这L话,可以不再象以往那样要通过在web.xml中对servletq行配置Q十分方ѝ?/p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;">此外QServlet 3.0提供了既能在容器中动态注册servlet的方法,也提供了通过实现</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;">ServletContainerInitializer接口的方法实现在容器启动阶段为容器动态注册Servlet、Filter和listeners。容器会在应用的启动阶段Q调用所有实现ServletContainerInitializer接口cM的onStartup()Ҏ。而Spring 3.2中,则进一步简化了q点Q只需要实现WebApplicationInitializer接口可以了Q其中提供了一个相关的实现c-QAbstractContextLoaderInitializerQ它可以动态注册DispatcherServlet。这意味着Q只要spring-webmvc.jar攄在web应用的web-inf/lib中,可以调用Dispatcher servlet了。可以参考如下的例子Q来自Spring文档Q:</p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 590.8333740234375px; overflow: auto; background-color: #e6e6e6; line-height: 27.986112594604492px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> MyWebApplicationInitializer </span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">implements</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> WebApplicationInitializer { </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@Override</span> </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> onStartup(ServletContext container) { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        ServletRegistration.Dynamic registration = container.addServlet(<span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"dispatcher"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, </span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> DispatcherServlet()); </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        registration.setLoadOnStartup(<span style="margin: 0px; padding: 0px; border: none; color: #c00000; background-color: inherit;">1</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        registration.addMapping(<span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"/example/*"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">); </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><strong>二 支持Java</strong><strong>~程式配|?/strong><strong></strong>在Spring mvc 3.2中,一个不错的Ҏ就是在之前版本中支持用Java代码配置各种依赖注入的基上,q一步简化了配置。关于用Java~程式配|的好处Q可以通过下面q个链接文章的介l去学习</p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;">Q?a _ style="color: #004276;">http://blog.frankel.ch/consider-replacing-spring-xml-configuration-with-javaconfig</a>Q?br style="clear: both; width: 0px; height: 0px;" />在Spring mvc 3.2中,提供?span style="background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">AbstractContextLoaderInitialize</span><span style="background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">的一个子c?/span><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">AbstractAnnotationConfigDispatcherServletInitializer</span></code><span style="background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">d现零</span><span style="background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">XML</span><span style="background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">配置的效果,只需要创建的cȝ?/span><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">AbstractAnnotationConfigDispatcherServletInitializer</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">可以了Q如下代码所C:</span></code></p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 590.8333740234375px; overflow: auto; background-color: #e6e6e6; line-height: 27.986112594604492px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">SugarSpringWebInitializer <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">extends</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> AbstractAnnotationConfigDispatcherServletInitializer { </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@Override</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">protected</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Class<?>[] getRootConfigClasses() { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">return</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Class[] { JavaConfig.</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> }; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@Override</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">protected</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Class<?>[] getServletConfigClasses() { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">return</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Class[] { WebConfig.</span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> }; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@Override</span> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">protected</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> String[] getServletMappings() { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">return</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> String[] { </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"/"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> }; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"> </li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><strong><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">?/span><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">功能更强大的</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">Spring Test </span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">框架</span></code></strong><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;"><strong></strong></span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">现在Q单元测试显得越来越重要了,每一个类都徏议做好对应的单元试。在</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">Spring 3.2</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">版本之前Q如果要?/span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">Spring MVC</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">q行单元试的话Q必L式去调用某个控制器类中的某个ҎQ而不能直接单元测试相关的</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">mapping</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">映射。而在</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">Spring mvc 3.2</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">中,重新整合和增Z试框架的功能,支持直接?/span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">/*</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">q样的映方式去试某个控制器中的类。同Ӟ之前的开源项目(</span></code><a _ style="color: #004276;"><span style="border: 1px windowtext; padding: 0px; background-color: white; background-position: initial initial; background-repeat: initial initial;">https://github.com/SpringSource/spring-test-mvc</span><span style="border: 1px windowtext; padding: 0px; background-color: white; background-position: initial initial; background-repeat: initial initial;">Q?/span><span style="border: 1px windowtext; padding: 0px; background-color: white; background-position: initial initial; background-repeat: initial initial;">也被收录?/span><span style="border: 1px windowtext; padding: 0px; background-color: white; background-position: initial initial; background-repeat: initial initial;">Spring mvc 3.2</span></a><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">中去?/span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">。此外,q新增加了对q回</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">(return)</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">Q重定向</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">(redirect)</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">?/span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">model</span></code><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">{的试改进Q下面是一个例子:</span></code></p><pre style="margin-top: 0px; padding: 0px; color: #333333; font-family: 'Courier New', monospace; font-size: 12px; width: 590.8333740234375px; overflow: auto; background-color: #e6e6e6; line-height: 27.986112594604492px;"><ol style="margin-left: 55px; padding: 5px 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; word-wrap: break-word; word-break: normal; border: none; background-color: #f7f7f7; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> SayHelloControllerIT </span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">extends</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> AbstractTestNGSpringContextTests { </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> MockMvc mockMvc; </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@BeforeMethod</span> </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> setUp() { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        mockMvc = webAppContextSetup((WebApplicationContext) applicationContext).build(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #646464; background-color: inherit;">@Test</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">(dataProvider = </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"pathParameterAndExpectedModelValue"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) </span></span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">public</span> <span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> accessingSayhelloWithSubpathShouldForwardToSayHelloJspWithModelFilled(String path, String value) </span><span style="margin: 0px; padding: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold;">throws</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Exception { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        mockMvc.perform(get(<span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"/sayHello/Jo"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)).andExpect(view().name(</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"sayHello"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)).andExpect(model().attribute(</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"name"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">, </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"Jo"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; color: inherit; list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    } </span></li><li style="list-style: none; word-wrap: break-word; word-break: normal; border: none; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-attachment: scroll; background-color: transparent; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-position: -498px -70px; background-repeat: no-repeat repeat;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">} </span></li></ol></pre><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">本文的示例代码可以在</span><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">:</span></code> <a _ style="color: #004276;"><span style="border: 1px windowtext; padding: 0px; background-color: white; background-position: initial initial; background-repeat: initial initial;">http://blog.frankel.ch/wp-content/resources/spring-3-2-sweetness/spring-sweet-1.0.0.zip</span></a><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">中下载?/span></code></p><p style="margin: 10px 0px; padding: 0px; color: #333333; background-color: #f8f8f8; text-indent: 28px; font-family: 宋体; font-size: 14.44444465637207px; line-height: 27.986112594604492px;"><code><span style="border: 1px windowtext; padding: 0px; background-color: white; color: #222222; background-position: initial initial; background-repeat: initial initial;">原文链接Q?a style="color: #004276;">http://java.dzone.com/articles/spring-32-sweetness</a></span></code></p><img src ="http://www.aygfsteel.com/ldwblog/aggbug/401397.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ldwblog/" target="_blank">David1228</a> 2013-07-10 11:48 <a href="http://www.aygfsteel.com/ldwblog/archive/2013/07/10/401397.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring2.5版本中用注解@Resource/@Antowired问题http://www.aygfsteel.com/ldwblog/archive/2013/03/21/396786.htmlDavid1228David1228Thu, 21 Mar 2013 02:22:00 GMThttp://www.aygfsteel.com/ldwblog/archive/2013/03/21/396786.htmlhttp://www.aygfsteel.com/ldwblog/comments/396786.htmlhttp://www.aygfsteel.com/ldwblog/archive/2013/03/21/396786.html#Feedback0http://www.aygfsteel.com/ldwblog/comments/commentRss/396786.htmlhttp://www.aygfsteel.com/ldwblog/services/trackbacks/396786.htmlSpring2.5l箋坚持了这个发展趋向,特别是ؓ那些使用Java 5或更新版本java的开发h员提供了q一步简化而强大的新特性。这些新Ҏ包括:注解驱动的依赖性注入(annotation-driven dependency injectionQ,使用注解而非XML元数据来自动侦测classpath上的SpringlgQ注解对生命周期Ҏ的支持,一个新的web控制器模型将h映射到加注解的方法上Q在试框架中支持Junit4QSpring XML命名I间的新增内容,{等?/div>
目中用的spring2.5版本。如果想要用spring提供的注解功?
applicationContext.xml配置文g中增加如下配|?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- Using annontations -->
<context:annotation-config></context:annotation-config>
新增以下三项才可以用注解功?span style="white-space:pre">
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config></context:annotation-config>
或?lt;bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/> 注册一个单独的Spring post-processor.
一个没有实CQ何接口的业务c,配置如下:
public class LogService extends Service{
public LogBiz(){}
@Resource //默认按名U查找bean. 如果找不刎ͼ则按cd匚wbean.
private BaseDao dao;
}
tomcat启动错误1Q?/div>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logBiz': Injection of resource fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ccms.base.dao.BaseDAO] is defined: expected single matching bean but found 40: [baseDAO, loginDAO, logDAO]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:876)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:437)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 32 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ccms.base.dao.BaseDAO] is defined: expected single matching bean but found 40: [baseDAO, loginDAO, logDAO]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:583)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:418)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:497)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:145)
at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:79)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessAfterInstantiation(CommonAnnotationBeanPostProcessor.java:288)
... 42 more
使用@Resource默认按名U查找bean. 如果找不刎ͼ则按cd匚wbean.而名Udao没有扑ֈQ所以会ҎBaseDAO匚wQ但是BaseDAO是一个接口:
<bean id="loginDAO" class="com.test.dao.loginDAO" parent="baseDAO" />
<bean id="logDAO" class="com.test.dao.logDAO" parent="baseDAO" />
<bean id="baseDAO" class="com.ccms.base.dao.BaseDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="simpleJdbcTemplate">
<ref bean="simpleJdbcTemplate" />
</property>
</bean>
有两个实CBaseDAO接口的类Q所以spring׃知道应该使用哪一个了。直接抛出异常?/div>
解决Ҏ1Q?/div>
我们可以看到baseDAO名称是唯一的, 所以如果想要按照名U匹配,则直接写baseDAO可以了
@Resource
private BaseDAO baseDAO;
解决Ҏ2Q?/div>
@Autowired //默认按照cd匚wQ同样应为有两个子类beanQ所以抛出异常?/div>
@Qualifier("loginDAO") //限定bean
private BaseDAO dao;
参考博客:
http://doc.chinaunix.net/java/200801/240056.shtml
http://stackoverflow.com/questions/10534053/autowiring-two-beans-implementing-same-interface-how-to-set-default-bean-to-au


David1228 2013-03-21 10:22 发表评论
]]>目标对象没有实现M接口QSpring使用CGLIB库生成目标对象的子类http://www.aygfsteel.com/ldwblog/archive/2013/03/05/396081.htmlDavid1228David1228Tue, 05 Mar 2013 06:54:00 GMThttp://www.aygfsteel.com/ldwblog/archive/2013/03/05/396081.htmlhttp://www.aygfsteel.com/ldwblog/comments/396081.htmlhttp://www.aygfsteel.com/ldwblog/archive/2013/03/05/396081.html#Feedback0http://www.aygfsteel.com/ldwblog/comments/commentRss/396081.htmlhttp://www.aygfsteel.com/ldwblog/services/trackbacks/396081.html然后我更C码后执行pȝ中的该模块,发现部分表数据没有完整持久到数据库中。看了下代码和spring配置文gQ原来调整后的Biz的业务类没有配置事务D的?br />
修改了下spring配置文gQbeanNamesl定?BizQ?
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <bean id= "propertyConfigurer"          
        class 
= "com.ccms.base.util.DecryptPropertyPlaceholderConfigurer" >          
     <property name="locations" value= "classpath:sysConfig.properties" />          
   </bean>      
    <!-- 
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>${dataSource.jdbcUrl}&amp;useUnicode=true&amp;characterEncoding=UTF-8</value>
        </property>
        <property name="username">
            <value>${dataSource.userName}</value>
        </property>
        <property name="password">
            <value>${dataSource.password}</value>
        </property>
        <property name="maxActive">
            <value>100</value>
        </property>
        <property name="initialSize">
            <value>5</value>
        </property>
        <property name="maxIdle">
            <value>10</value>
        </property>
        <property name="minIdle">
            <value>0</value>
        </property>
        <property name="maxWait">
            <value>-1</value>
        </property>
        <property name="defaultAutoCommit">
            <value>false</value>
        </property>
        <property name="testOnBorrow">
            <value>true</value>
        </property>
        <property name="testWhileIdle">
            <value>true</value>
        </property>
        <property name="timeBetweenEvictionRunsMillis">
            <value>600000</value>
        </property>
        <property name="numTestsPerEvictionRun">
            <value>20</value>
        </property>
        <property name="minEvictableIdleTimeMillis">
            <value>3600000</value>
        </property>
    </bean>
   
-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="${dataSource.jdbcUrl}&amp;useUnicode=true&amp;characterEncoding=UTF-8" />
        <property name="user" value="${dataSource.userName}" />
        <property name="password" value="${dataSource.password}" />
          <property name="minPoolSize" value="5" />
        <property name="maxPoolSize" value="50" />
        <property name="maxStatements" value="0" />
        <property name="idleConnectionTestPeriod" value="60" />
        <property name="acquireRetryAttempts" value="3" />
    </bean>

    <!-- Session Factory -->
    <bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
    <!-- hbm配置文g的classPath路径 -->
        <property name="mappingDirectoryLocations">
            <list>
                <value>classpath:/com/ccms/base/mapping</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.connection.release_mode">auto</prop>
                <prop key="hibernate.autoReconnect">true</prop> 
                <prop key="hibernate.connection.autocommit">false</prop>
                <!-- <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop> -->
            </props>
        </property>
    </bean>

    <bean id="myTransactionManager"
        class
="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean> 

    <bean id="transactionInterceptor"
        class
="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="myTransactionManager" />
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
            </props>
        </property>
    </bean>
    <bean  class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
        <property name="transactionInterceptor"
            ref
="transactionInterceptor" />
    </bean>
    <bean
        
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <list>
                <value>*Service</value>
                <value>*Biz</value>
            </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>
</beans>

启动tomcat后报出如下错误信息:
[2013-03-05 10:36:56] [ERROR] Context initialization failed - at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215) 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginBiz' defined in ServletContext resource [/WEB-INF/spring-service-resource.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
... 28 more
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:718)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
... 34 more
2013-3-5 10:36:56 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginBiz' defined in ServletContext resource [/WEB-INF/spring-service-resource.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ccms.login.LoginBiz]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
... 28 more
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:718)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
... 34 more
2013-3-5 10:36:56 org.apache.catalina.core.StandardContext start

------------------------------------------
通过以上错误分析之:对于实现了接口的c,直接用了JDK的动态代理,把目标对象扔lJDK的ProxyQ拿C理对象就OK了?/span>然而对于没有实现接口的c,Spring借助于CGLIB来实C理?br />解决办法Q?br />当用CGLIB来实C理后Q没有实现接口的c?br />1?通过构造函数Ş式注入时必须有默认的构造函敎ͼ否则׃出现上面的异常?br />2、通过生setter或者getterҎ注入?br />3、通过修改Spring?span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px; background-color: #fafafa;">CglibProxyFactory工厂cR?br />
详细解析可以参照q篇文章Q?a >http://netfork.iteye.com/blog/286215

David1228 2013-03-05 14:54 发表评论
]]>
Spring使用Quartz调度?实现旉点Q?Spring in Action中文? http://www.aygfsteel.com/ldwblog/archive/2011/09/14/358587.htmlDavid1228David1228Wed, 14 Sep 2011 02:19:00 GMThttp://www.aygfsteel.com/ldwblog/archive/2011/09/14/358587.htmlhttp://www.aygfsteel.com/ldwblog/comments/358587.htmlhttp://www.aygfsteel.com/ldwblog/archive/2011/09/14/358587.html#Feedback0http://www.aygfsteel.com/ldwblog/comments/commentRss/358587.htmlhttp://www.aygfsteel.com/ldwblog/services/trackbacks/358587.htmlhttp://chorpin.iteye.com/blog/157992

http://www.quartz-scheduler.org/documentation

7.3.2  使用Quartz调度?
Quartz调度器ؓ调度工作提供了更丰富的支持。和Java定时器一P可以使用Quartz来每隔多毫U执行一个工作。但Quartz比Java Timer更先q之处在于它允许你调度一个工作在某个特定的时间或日期执行?

关于Quartz的更多信息,可以讉KQuartz位于http://www.opensymphony.com/quartz的主c?

让我们从定义发送报表邮件的工作开始用QuartzQ?

创徏一个工?
定义Quartz工作的第一步是创徏一个类来定义工作。要做到q一点,你需要从Spring的QuartzJobBean中派生子c,如程序清?.3所C:

 E序清单7.3  定义一个Quartz工作
  public class EmailReportJob extends QuartzJobBean {
    public EmailReportJob() {}
    protected void executeInternal(JobExecutionContext context)
        throws JobExecutionException {
      courseService.sendCourseEnrollmentReport();
    }

    private CourseService courseService;
    public void setCourseService(CourseService courseService) {
      this.courseService = courseService;
    }
  }

QuartzJobBean是Quartz中与Java的TimerTask{h的类。它实现了org.quartz.Job接口。executeInternal()Ҏ定义了当预定的时L临时应该执行哪些动作。在q里Q正如EmailReportTaskQ你只是单地调用了courseService属性的sendCourseEnrollmentReport()Ҏ?

在Spring配置文g中按以下方式声明q个工作Q?
  <bean id="reportJob"
       class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass">
      <value>com.springinaction.training.
           schedule.EmailReportJob</value>
    </property>
    <property name="jobDataAsMap">
      <map>
        <entry key="courseService">
          <ref bean="courseService"/>
        </entry>
      </map>
    </property>
  </bean>

值得注意的是Q在q里你ƈ没有直接声明一个EmailReportJob BeanQ而是声明了一个JobDetailBean。这是用Quartz时的一个特炏VJobDetailBean是Quartz的org.quartz.JobDetail的子c,它要求通过jobClass属性来讄一个Job对象?

使用Quartz的JobDetail中的另一个特别之处是EmailReportJob的courseService属性是间接讄的。JobDetail的jobDataAsMap属性接受一个java.util.MapQ其中包含了需要设|给jobClass的各U属性。在q里Q这个map包含了一个指向courseService Bean的引用,它的键gؓcourseService。当JobDetailBean实例化时Q它会将courseService Bean注入到EmailReportJob的courseService属性中?

调度工作
现在工作已经被定义好了,接下来你需要调度这个工作。Quartz的org.quartz.TriggercLqC何时及以怎样的频度运行一个Quartz工作。Spring提供了两个触发器QSimpleTriggerBean和CronTriggerBean。你应该使用哪个触发器?让我们分别考察一下这两个触发器,首先从SimpleTriggerBean开始?

SimpleTriggerBean与ScheduledTimerTaskcM。你可以用它来指定一个工作应该以怎样的频度运行,以及Q可选地Q在W一ơ运行工作之前应该等待多久。例如,要调度报表工作每24时q行一ơ,W一ơ在1时之后开始运行,可以按照以下方式q行声明Q?

  <bean id="simpleReportTrigger"       class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail">
      <ref bean="reportJob"/>
    </property>
    <property name="startDelay">
      <value>3600000</value>
    </property>
    <property name="repeatInterval">
      <value>86400000</value>
    </property>
  </bean>

属性jobDetail装配了将要被调度的工作,在这个例子中是reportJob Bean。属性repeatInterval告诉触发器以怎样的频度运行这个工作(以毫U作为单位)。这里,我们讄它ؓ86400000Q因此每?4时它会被触发一ơ。你也可以选择讄startDelay属性来延迟工作的第一ơ执行。我们设|它?600000Q因此在W一ơ触发之前它会等?时?

调度一个cron工作
管你可能认为SimpleTriggerBean适用于大多数应用Q但它仍然不能满_送注册报表邮件的需求。正如ScheduledTimerTaskQ你只能指定工作执行的频度,而不能准指定它于何时运行。因此,你无法用SimpleTriggerBean在每天早?:00l课E主d送注册报表邮件?

然而,CronTriggerBean允许你更_地控制Q务的q行旉。如果你对Unix的cron工具很熟悉,则会觉得CronTriggerBean很亲切。你不是定义工作的执行频度,而是指定工作的准运行时_和日期)。例如,要在每天早上6:00q行报表工作Q可以按照以下方式声明一个CronTriggerBeanQ?

  <bean id="cronReportTrigger"
       class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail">
      <ref bean="reportJob"/>
    </property>
    <property name="cronExpression">
      <value>0 0 6 * * ?</value>
    </property>
  </bean>

和SimpleTriggerBean一PjobDetail属性告诉触发器调度哪个工作。这里我们又一ơ装配了一个reportJob Bean。属性cronExpression告诉触发器何时触发。如果你不熟悉cronQ这个属性可能看上去有点秘Q因此让我们q一步考察一下这个属性?

一个cron表达式有臛_6个(也可能是7个)q格分隔的旉元素。从左至叻Iq些元素的定义如下:

1Q秒Q?–59Q?

2Q分钟(0–59Q?

3Q小Ӟ0–23Q?

4Q月份中的日期(1–31Q?

5Q月份(1–12或JAN–DECQ?

6Q星期中的日期(1–7或SUN–SATQ?

7Q年份(1970–2099Q?

每一个元素都可以昑ּ地规定一个|?Q,一个区_?-12Q,一个列表(?Q?1Q?3Q或一个通配W(?Q?#8220;月䆾中的日期”?#8220;星期中的日期”q两个元素是互斥的,因此应该通过讄一个问PQ)来表明你不想讄的那个字Dc表7.1中显CZ一些cron表达式的例子和它们的意义Q?

?.1                                            一些cron表达式的例子

?nbsp; ?nbsp; ?
?nbsp;   ?

0 0 10,14,16 * * ?
每天上午10点,下午2点和下午4?
0 0,15,30,45 * 1-10 * ?
每月?0天每?5分钟
30 0 0 1 1 ? 2012
?012q??日午夜过30U时
0 0 8-5 ? * MON-FRI
每个工作日的工作旉

对于cronReportTriggerQ我们设|cronExpression? 0 6 * * ?可以把它M“在Q何月份Q何日期(不管是星期几Q的6??U执行触发器?#8221;换句话说Q这个触发器会在每天早晨6:00执行?
使用CronTriggerBean完全能够满评MQ的期望了。现在剩下要做的只是启动q个工作了?
启动工作
Spring的SchedulerFactoryBean是Quartz中与TimerFactoryBean{h的类。按照如下方式在Spring配置文g中声明它Q?
  <bean class="org.springframework.scheduling.
         quartz.SchedulerFactoryBean">
    <property name="triggers">
      <list>
        <ref bean="cronReportTrigger"/>
      </list>
    </property>
  </bean>

属性triggers接受一l触发器。由于目前只有一个触发器Q因此只需单地装配一个包含cronReportTrigger Bean的一个引用的列表卛_?
现在Q你已经实现了调度发送注册报表邮件的需求。但在这个过E中Q你做了一些额外的工作。在开始新的话题之前,首先让我们看一下如何通过更简单一些的方式调度报表邮g?

CZ配置Q?
<beans>
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<!--ref local="SocketJobTrigger"/>
                <ref local="RouteJobTrigger"/-->
</list>
</property>
</bean>
<!---->
<bean id="SocketJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="SocketJobDetail"/>
</property>
<property name="startDelay">    
    <value>10000</value>
  </property>
  <property name="repeatInterval">
    <!-- repeat every 2 minutes -->
    <value>120000</value>
  </property>
</bean>
<bean id="SocketJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref local="quartzManager"/>
</property>
<property name="targetMethod">
<value>useQuartz</value>
</property>
</bean>

<bean id="socketManager" class="com.lxh.bean.quartzManager">
</bean>
<!---->
<bean id="RouteJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="RouteJobDetail"/>
</property>
<property name="startDelay">    
    <value>30000</value>
  </property>
  <property name="repeatInterval">
    <value>30000</value>
  </property>
</bean>
<bean id="RouteJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref local="otherManager"/>
</property>
<property name="targetMethod">
<value>otherQuartz</value>
</property>
</bean>

<bean id="routeManager" class="com.lxh.job.otherManager">
</bean>
</beans>


David1228 2011-09-14 10:19 发表评论
]]>
Spring创始人Rod Johnson加盟VMware一事表C兴?/title><link>http://www.aygfsteel.com/ldwblog/archive/2011/08/22/357043.html</link><dc:creator>David1228</dc:creator><author>David1228</author><pubDate>Mon, 22 Aug 2011 07:09:00 GMT</pubDate><guid>http://www.aygfsteel.com/ldwblog/archive/2011/08/22/357043.html</guid><wfw:comment>http://www.aygfsteel.com/ldwblog/comments/357043.html</wfw:comment><comments>http://www.aygfsteel.com/ldwblog/archive/2011/08/22/357043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ldwblog/comments/commentRss/357043.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ldwblog/services/trackbacks/357043.html</trackback:ping><description><![CDATA[<div style="text-indent: 28px;"><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: 宋体; line-height: 28px; ">转蝲自:</span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: 宋体; line-height: 28px; ">  <a >http://developer.51cto.com/art/200908/143288.htm</a></span></div><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: 宋体; line-height: 28px; "><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><br /></p></span><span id="wmqeeuq" class="Apple-style-span" style="color: #333333; font-family: 宋体; line-height: 28px; "><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><a style="color: #004276; text-decoration: underline; ">VMware斥资4.2亿美元收购SpringSource</a>Q?.6亿现金外?800万股份)Q目的在于从虚拟化厂商升Uؓ云计的重要参与者?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">VMware的CTOSteve HerrodUVMware的vSphere云管理^CSpring Java应用框架{工Ll合会大大节省开发者编写部|应用所p的时间精力。此丑ְ提升VMware在PaaS上的竞争能力。PaaS上的几大竞争者包括Salesforce.com的Force.comQ以及Google App Engine?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">Rod Johnson在SpringSource官方博客上公布这一消息时声U收购将于今q第三季度完成,届时SpringSource成为VMware下属的一个部门,而他仍是SpringSource的领D?strong style="font-weight: bold; text-align: center; ">以下是Rod JohnsonҎơ收购的展望Q?/strong></p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">“此次军_是很自然而符合逻辑的:q将带来更多的新技术,q且对Spring框架以及SpringC֌都有好处?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><strong style="font-weight: bold; text-align: center; ">我很兴奋</strong>。希望你也是。这极其有?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">……Spring框架l提供优质的企业UJava支持。我们从x开发者如何创建和使用应用Q到x他们如何部v和运行企业应用Qؓ此我们创Zdm Server和tc Server。我?a style="color: #004276; text-decoration: underline; ">收购Hyperic</a>也是Z改善开发者管理企业应用的方法?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">然而IT的发展要q远过Java框架Q工具以及运行时基础设施。h们对于Y件堆栈的x正在改变。虚拟化改变了数据中心,而云计算又将走的更远。云计算开发与操作的界限模p化Qƈ赋予开发者更多的力量Q与责QQ?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">现在的问题就是,如何SpringSource在数据中心和云计中的潜力:它的单,强大和实用这些好处最大化Q我们今q早些时候曾试q在VMware的Lab Manager下的虚拟Zq行SpringSource Tool Suite中的Spring应用。这ơ范例的反响很好。而VMware的vApp concept又能够将不同的机器映像,中间件以及管理控件结合到一?#8212;—点击一下,p在数据中心和云端q行Q这都是很好的蓝图?/p><p align="center" style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; "><a target="_blank" style="color: #004276; text-decoration: underline; "><img class="fit-image" height="314" alt="创徏-q行-理" src="http://images.51cto.com/files/uploadimg/20090811/134244490.jpg" width="494" border="0" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-color: initial; text-align: center; border-style: initial; border-color: initial; " /></a> </p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">与VMware的合作中Q我们计划创Z个简单,集成Q创?q行-理合一的数据中心、私有云和公׃的解x案。这个方案将融合应用架构的知识,q带中间件以及管理控Ӟ保一个虚拟环境在部vq程中以及运行时的最大效率及Ҏ。这是一个PaaSQ徏立在你已知的技术之上,从而最大的减少p与复杂度。这是一个围l开源、可UL的中间g技术的解决ҎQ既可以在传l数据中心的Java EE应用服务器上q行Q又可以在如Amazon EC2之类的弹性云上运行,也可以在VMwareq_上运行?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">……与VMware的vSphere以及其他云技术一P我们在框架和基设施上带来一个全新的体验。SpringSource的应用框架、服务器及管理Y件将成ؓVMwareq_的眼睛和x?/p><p style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #333333; background-color: transparent; text-indent: 28px; ">……SpringSource的下一步工作将是这些新的挑战:Z我们的Build/Run/ManageQ创行管理)pȝQ提供从桌面端到云端的最佌x案。让百万Java开发者都能n受到云计带来的好处?#8221;</p></span><br /><a ></a><img src ="http://www.aygfsteel.com/ldwblog/aggbug/357043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ldwblog/" target="_blank">David1228</a> 2011-08-22 15:09 <a href="http://www.aygfsteel.com/ldwblog/archive/2011/08/22/357043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">봨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ѽ</a>| <a href="http://" target="_blank">ɫ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank">ϼ</a>| <a href="http://" target="_blank">¸</a>| <a href="http://" target="_blank">ľ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʼ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">¡</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ɽ</a>| <a href="http://" target="_blank">ѧ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">͡</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ݰ</a>| <a href="http://" target="_blank"></a>| <a href="http://" 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>