ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>午夜久久免费观看,国产成人精品一区二区三区视频,国产视频久久久久http://www.aygfsteel.com/javaora/category/1829.htmlzh-cnTue, 27 Feb 2007 10:49:46 GMTTue, 27 Feb 2007 10:49:46 GMT60再看JPetstore所惛_ˆ°çš?/title><link>http://www.aygfsteel.com/javaora/archive/2005/10/19/16065.html</link><dc:creator>java世界畅谈</dc:creator><author>java世界畅谈</author><pubDate>Wed, 19 Oct 2005 15:47:00 GMT</pubDate><guid>http://www.aygfsteel.com/javaora/archive/2005/10/19/16065.html</guid><wfw:comment>http://www.aygfsteel.com/javaora/comments/16065.html</wfw:comment><comments>http://www.aygfsteel.com/javaora/archive/2005/10/19/16065.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/javaora/comments/commentRss/16065.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/javaora/services/trackbacks/16065.html</trackback:ping><description><![CDATA[<P>  ˜q™äº›å¤©åœ¨¾l†çœ‹ã€ŠJ2EE Development without EJB》书åQŒæ„Ÿå—颇多。说èµäh¥åšJ2EEæ–šw¢å¼€å‘也有几òqß_¼Œè‡ªå·±è®¤äؓ自己˜q˜æ˜¯æœ‰ä¸€å®šå®žåŠ›çš„ã€‚ä½†æ˜¯çœ‹å®Œä»¥åŽï¼Œå†é’ˆå¯ÒŽˆ‘们项目的开发感觉很多地方做的确实有很多问题。因ä¸ÞZ¸€ç›´éƒ½˜q™æ ·åšï¼Œæ²¡æœ‰äººæå‡ºå¼‚议。闷着头做事情åQŒæœ‰æ—¶å€™ç¡®å®žä¸å¥½ï¼Œè¦äº¤‹¹ï¼Œç‰¹åˆ«æ˜¯è¦å€‘֐¬é‚£äº›¾léªŒä¸°å¯Œçš„前辈的教诲ã€?BR>  OOåQŒæŽ¥è§¦å¼€å‘也˜q™ä¹ˆå¤šå¹´äº†ï¼Œ¼‹®å®žå¾ˆå°‘有项目,真正做到OO的。看看我们的™å¹ç›®åQŒPOJO做成伪对象,只是负责了值的传递,只有可怜的setterå’ŒgetteråQŒå…¶ä¸­æ²¡æœ‰ä“Q何业务逻辑操作的代码(没有ä»ÖM½•è¡ŒäØ“åQ‰ã€‚我们所谓的业务逻辑是引入一个Manager˜q›è¡Œ¾l¼åˆå¤„理ã€?BR>  åQ‘年前,也是看了jPetStore收益很多。今天再‹Æ¡çœ‹˜q™ä¸ªä»£ç ã€‚又引发了更多的思考ã€?BR>  先看jPetstore的处理:<BR>  在org.springframework.sample.jpetstore包中åQ?BR>  Account¾c»ï¼šæ¯”较½Ž€å•,普通的JavaBeanã€?BR>  Cart¾cÕd’ŒCarItem¾c»ï¼šä»Žå…³¾pÀL¨¡åž‹ä¸­åQŒå¯ä»¥çœ‹åˆ°è¿™æ˜¯ä¸€ä¸ªä¸»ä»Žå…³¾pȝš„对象。其中CartåQˆè´­ç‰©èžRåQ‰ä¸­æœ‰ä¸ž®‘行为。例如:新增、删除购物èžR™å¹ç›®åQ›è®¡½Ž—总金额。一般来è¯ß_¼Œæˆ‘们™å¹ç›®ä¸­ä¸€èˆ¬è¿™æ ïLš„逻辑是写在Manager¾cÖM¸­çš„ã€?BR>  在Order¾cÖM¸­åQŒä¹Ÿé‡‡ç”¨ä¸€äº›ä¸šåŠ¡è¡Œä¸ºï¼Œä¾‹å¦‚åˆå§‹åŒ–è®¢å•ç­‰½{‰ã€?BR>  </P><img src ="http://www.aygfsteel.com/javaora/aggbug/16065.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/javaora/" target="_blank">java世界畅谈</a> 2005-10-19 23:47 <a href="http://www.aygfsteel.com/javaora/archive/2005/10/19/16065.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Springé‚®äšg抽象层发送邮ä»?/title><link>http://www.aygfsteel.com/javaora/archive/2005/07/25/8386.html</link><dc:creator>java世界畅谈</dc:creator><author>java世界畅谈</author><pubDate>Mon, 25 Jul 2005 03:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/javaora/archive/2005/07/25/8386.html</guid><wfw:comment>http://www.aygfsteel.com/javaora/comments/8386.html</wfw:comment><comments>http://www.aygfsteel.com/javaora/archive/2005/07/25/8386.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/javaora/comments/commentRss/8386.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/javaora/services/trackbacks/8386.html</trackback:ping><description><![CDATA[<P>Sending Email with Spring mail abstraction layer<BR>使用Springé‚®äšg抽象层发送邮ä»Óž¼š<BR>18.1. Introduction<BR>介绍<BR>Spring provides a higher level of abstraction for sending electronic mail which shields the user from the specifics of underlying mailing system and is responsible for a low level resource handling on behalf of the client.</P> <P>Spring 支持一个更高层的抽象用来发送电子邮ä»Óž¼Œå®ƒéšè—åº•层邮件系¾lŸçš„¾l†èŠ‚òq¶ä¸”代表客户端对低çñ”别的控制 ã€?/P> <P>18.2. Spring mail abstraction structure<BR>Springé‚®äšg抽象¾l“æž„<BR>The main package of Spring mail abstraction layer is org.springframework.mail package. It contains central interface for sending emails called MailSender and the value object which encapsulates properties of a simple mail such as from, to, cc, subject, text called SimpleMailMessage. This package also contains a hierarchy of checked exceptions which provide a higher level of abstraction over the lower level mail system exceptions with the root exception being MailException.Please refer to JavaDocs for more information on mail exception hierarchy.</P> <P>Sringé‚®äšg抽象层的主要包是åQšorg.springframework.mail 包。它包含叫MailSender为发送邮件的核心接口和包含简单邮件属性例如from,to,cc,subject,text叫SimpleMailMessage的值对è±? ˜q™ä¸ªåŒ…也包含一个检查异常的层次åQŒå®ƒæ”¯æŒä¸€ä¸ªæ›´é«˜çñ”别的抽象­‘…过低çñ”别的邮äšg¾pȝ»Ÿå¼‚常伴随根异常存在MailException. 请参考JavaDocs为更多的信息杂邮件异常层‹Æ¡ã€?/P> <P>Spring also provides a sub-interface of MailSender for specialized JavaMail features such as MIME messages, namely org.springframework.mail.javamail.JavaMailSender It also provides a callback interface for preparation of JavaMail MIME messages, namely org.springframework.mail.javamail.MimeMessagePreparator</P> <P>Spring也支持一个MailSender的专用于JavaMail特征例如MIME消息子接口,命名为org.springframework.javamail.JavaMailerSenerã€‚å®ƒä¹Ÿæ”¯æŒä¸€ä¸ªäØ“JavaMail MIME信息的准备回调接口,命名为org.springframework.mail.JavaMail.MimeMessagePreparator.</P> <P>MailSender: </P> <P>public interface MailSender {</P> <P>    /**<BR>     * Send the given simple mail message.<BR>     * @param simpleMessage message to send<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     * 发送给定的½Ž€å•邮件信æ?BR>     * @参数 simpleMessage  发送的信息<BR>     * @throws MailException 假设信息åQŒè¯æ˜Žæˆ–发送错è¯?BR>     */<BR>     <BR>    public void send(SimpleMailMessage simpleMessage) throws MailException;</P> <P>    /**<BR>     * Send the given array of simple mail messages in batch.<BR>     * @param simpleMessages messages to send<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     */<BR>    public void send(SimpleMailMessage[] simpleMessages) throws MailException;</P> <P>}</P> <P>JavaMailSender: </P> <P>public interface JavaMailSender extends MailSender {</P> <P>    /**<BR>     * Create a new JavaMail MimeMessage for the underlying JavaMail Session<BR>     * of this sender. Needs to be called to create MimeMessage instances<BR>     * that can be prepared by the client and passed to send(MimeMessage).<BR>     * @return the new MimeMessage instance<BR>     * @see #send(MimeMessage)<BR>     * @see #send(MimeMessage[])<BR>     * 创徏一个新的JavaMail MimeMessage 为潜在的JavaMail的发送者的会话.<BR>     * 需要被调用来创建MimeMessage实例åQŒå®ƒå¯ä»¥è¢«å®¢æˆ·å‡†å¤‡åƈ且被传递发é€?MimeMessage).<BR>     * @return ˜q™ä¸ªæ–°çš„MimeMessage 实例<BR>     * @see #send(Message)<BR>     * @sess #send(MimeMessage[])<BR>     */<BR>    public MimeMessage createMimeMessage();</P> <P>    /**<BR>     * Send the given JavaMail MIME message.<BR>     * The message needs to have been created with createMimeMessage.<BR>     * @param mimeMessage message to send<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     * @see #createMimeMessage<BR>     */<BR>    public void send(MimeMessage mimeMessage) throws MailException;</P> <P>    /**<BR>     * Send the given array of JavaMail MIME messages in batch.<BR>     * The messages need to have been created with createMimeMessage.<BR>     * @param mimeMessages messages to send<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     * @see #createMimeMessage<BR>     */<BR>    public void send(MimeMessage[] mimeMessages) throws MailException;</P> <P>    /**<BR>     * Send the JavaMail MIME message prepared by the given MimeMessagePreparator.<BR>     * Alternative way to prepare MimeMessage instances, instead of createMimeMessage<BR>     * and send(MimeMessage) calls. Takes care of proper exception conversion.<BR>     * @param mimeMessagePreparator the preparator to use<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     */<BR>    public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException;</P> <P>    /**<BR>     * Send the JavaMail MIME messages prepared by the given MimeMessagePreparators.<BR>     * Alternative way to prepare MimeMessage instances, instead of createMimeMessage<BR>     * and send(MimeMessage[]) calls. Takes care of proper exception conversion.<BR>     * @param mimeMessagePreparators the preparator to use<BR>     * @throws MailException in case of message, authentication, or send errors<BR>     */<BR>    public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException;</P> <P>}<BR>MimeMessagePreparator: </P> <P>public interface MimeMessagePreparator {</P> <P>    /**<BR>     * Prepare the given new MimeMessage instance.<BR>     * @param mimeMessage the message to prepare<BR>     * @throws MessagingException passing any exceptions thrown by MimeMessage<BR>     * methods through for automatic conversion to the MailException hierarchy<BR>     */<BR>    void prepare(MimeMessage mimeMessage) throws MessagingException;</P> <P>}</P> <P>18.3. Using Spring mail abstraction<BR>使用Springé‚®äšg抽象<BR>Let's assume there is a business interface called OrderManager<BR>让我们假定这里有一个商业接口叫OrderManager</P> <P>public interface OrderManager {</P> <P>    void placeOrder(Order order);<BR>    <BR>}</P> <P>and there is a use case that says that an email message with order number would need to be generated and sent to a customer placing that order. So for this purpose we want to use MailSender and SimpleMailMessage<BR>òq¶ä¸”˜q™é‡Œæœ‰ä¸€ä¸ªæœ‰ç”¨æ¡ˆä¾‹ï¼Œå¯ä»¥è¯´ä¸€ä¸ªä¼´éšè®¢å•ç¼–åïLš„é‚®äšg信息ž®†éœ€è¦è¢«äº§ç”Ÿòq¶ä¸”å‘é€ç»™ä¸€ä¸ªå®¢æˆ·å¤„ç†è¿™ä¸ªè®¢å•ã€‚æ‰€ä»¥äØ“˜q™ä¸ªç›®çš„æˆ‘们惌™¦ä½¿ç”¨MailSenderå’ŒSimpleMailSender.</P> <P><BR>Please note that as usual, we work with interfaces in the business code and let Spring IoC container take care of wiring of all the collaborators for us.</P> <P>è¯äh³¨æ„ç…§å¸¸ï¼Œæˆ‘ä»¬å·¥ä½œä½¿ç”¨åœ¨å•†ä¸šä»£ç ä¸­çš„æŽ¥å£åÆˆä¸”è®©Spring Ioc 容器兛_¿ƒä¸ºæˆ‘们的所有合作者ã€?/P> <P>Here is the implementation of OrderManager <BR>˜q™é‡Œæ˜¯OrderManager的实çŽ?</P> <P>import org.springframework.mail.MailException;<BR>import org.springframework.mail.MailSender;<BR>import org.springframework.mail.SimpleMailMessage;</P> <P>public class OrderManagerImpl implements OrderManager {</P> <P>    private MailSender mailSender;<BR>    private SimpleMailMessage message;</P> <P>    public void setMailSender(MailSender mailSender) {<BR>        this.mailSender = mailSender;<BR>    }</P> <P>    public void setMessage(SimpleMailMessage message) {<BR>        this.message = message;<BR>    }</P> <P>    public void placeOrder(Order order) {</P> <P>        //... * Do the business calculations....<BR>        //... * Call the collaborators to persist the order</P> <P>        //Create a thread safe "sandbox" of the message<BR>        SimpleMailMessage msg = new SimpleMailMessage(this.message);<BR>        msg.setTo(order.getCustomer().getEmailAddress());<BR>        msg.setText(<BR>            "Dear "<BR>                + order.getCustomer().getFirstName()<BR>                + order.getCustomer().getLastName()<BR>                + ", thank you for placing order. Your order number is "<BR>                + order.getOrderNumber());<BR>        try{<BR>            mailSender.send(msg);<BR>        }<BR>        catch(MailException ex) {<BR>            //log it and go on<BR>            System.err.println(ex.getMessage());            <BR>        }<BR>    }<BR>}<BR>Here is what the bean definitions for the code above would look like:<BR>˜q™é‡Œæ˜¯è¿™ä¸ªäØ“˜q™ä¸ªä»¥ä¸Šä»£ç bean定义¾cÖM¼¼åQ?/P> <P><bean id="mailSender"<BR>      class="org.springframework.mail.javamail.JavaMailSenderImpl"><BR>    <property name="host"><value>mail.mycompany.com</value></property><BR></bean></P> <P><bean id="mailMessage"<BR>      class="org.springframework.mail.SimpleMailMessage"><BR>    <property name="from"><value>customerservice@mycompany.com</value></property><BR>    <property name="subject"><value>Your order</value></property><BR></bean></P> <P><bean id="orderManager"<BR>      class="com.mycompany.businessapp.support.OrderManagerImpl"><BR>    <property name="mailSender"><ref bean="mailSender"/></property><BR>    <property name="message"><ref bean="mailMessage"/></property><BR></bean><BR>Here is the implementation of OrderManager using MimeMessagePreparator callback interface. Please note that the mailSender property is of type JavaMailSender in this case in order to be able to use JavaMail MimeMessage: </P> <P>import javax.mail.Message;<BR>import javax.mail.MessagingException;<BR>import javax.mail.internet.InternetAddress;<BR>import javax.mail.internet.MimeMessage;</P> <P>import javax.mail.internet.MimeMessage;<BR>import org.springframework.mail.MailException;<BR>import org.springframework.mail.javamail.JavaMailSender;<BR>import org.springframework.mail.javamail.MimeMessagePreparator;</P> <P>public class OrderManagerImpl implements OrderManager {<BR>    private JavaMailSender mailSender;<BR>    <BR>    public void setMailSender(JavaMailSender mailSender) {<BR>        this.mailSender = mailSender;<BR>    }</P> <P>    public void placeOrder(final Order order) {</P> <P>        //... * Do the business calculations....<BR>        //... * Call the collaborators to persist the order<BR>        <BR>        <BR>        MimeMessagePreparator preparator = new MimeMessagePreparator() {<BR>            public void prepare(MimeMessage mimeMessage) throws MessagingException {<BR>                mimeMessage.setRecipient(Message.RecipientType.TO, <BR>                        new InternetAddress(order.getCustomer().getEmailAddress()));<BR>                mimeMessage.setFrom(new InternetAddress("<A href="mailto:mail@mycompany.com">mail@mycompany.com</A>"));<BR>                mimeMessage.setText(<BR>                    "Dear "<BR>                        + order.getCustomer().getFirstName()<BR>                        + order.getCustomer().getLastName()<BR>                        + ", thank you for placing order. Your order number is "<BR>                        + order.getOrderNumber());<BR>            }<BR>        };<BR>        try{<BR>            mailSender.send(preparator);<BR>        }<BR>        catch(MailException ex) {<BR>            //log it and go on<BR>            System.err.println(ex.getMessage());            <BR>        }<BR>    }<BR>}<BR>If you want to use JavaMail MimeMessage to the full power, the MimeMessagePreparator is available at your fingertips.<BR>如果你想使用JavaMail  MimeMessage来ä‹Éå¾—èƒö够强大,MimeMessagePreparator 是可以利用的ã€?/P> <P>Please note that the mail code is a crosscuttingåQˆæ¨ªåˆ‡çš„åQ?concernåQˆå…³æ³¨ï¼‰  and is a perfect candidateåQˆå€™é€‰ï¼‰ for refactoring into a custom Spring AOP advice, which then could easily be applied to OrderManager target. Please see the AOP chapter.</P> <P><BR>18.3.1. Pluggable MailSender implementations<BR>Spring comes with two MailSender implementations out of the box - the JavaMail implementation and the implementation on top of Jason Hunter's MailMessage class that's included in <A >http://servlets.com/cos</A> (com.oreilly.servlet). Please refer to JavaDocs for more information.</P> <P>18.4. Using the JavaMail MimeMessageHelper<BR>One of the components that comes in pretty handy when dealing with JavaMail messages is the org.springframework.mail.javamail.MimeMessageHelper. It prevents you from having to use the nasty APIs the the javax.mail.internet classes. A couple of possible scenarios: </P> <P>18.4.1. Creating a simple MimeMessage and sending it<BR>Using the MimeMessageHelper it's pretty easy to setup and send a MimeMessage: </P> <P>// of course you would setup the mail sender using <BR>// DI in any real-world cases<BR>JavaMailSenderImpl sender = new JavaMailSenderImpl();<BR>sender.setHost("mail.host.com");</P> <P>MimeMessage message = sender.createMimeMesage();<BR>MimeMessageHelper helper = new MimeMessageHelper(message);<BR>helper.setTo("<A href="mailto:test@host.com">test@host.com</A>");<BR>helper.setText("Thank you for ordering!");</P> <P>sender.send(message);</P> <P>18.4.2. Sending attachments and inline resources<BR>Email allow for attachments, but also for inline resources in multipart messages. Inline resources could for example be images or stylesheet you want to use in your message, but don't want displayed as attachment. The following shows you how to use the MimeMessageHelper to send an email along with an inline image. </P> <P>JavaMailSenderImpl sender = new JavaMailSenderImpl();<BR>sender.setHost("mail.host.com");</P> <P>MimeMessage message = sender.createMimeMesage();</P> <P>// use the true flag to indicate you need a multipart message<BR>MimeMessageHelper helper = new MimeMessageHelper(message, true);<BR>helper.setTo("<A href="mailto:test@host.com">test@host.com</A>");</P> <P>// use the true flag to indicate the text included is HTML<BR>helper.setText(<BR>  "<html><body><img src='cid:identifier1234'></body></html>"<BR>  true);</P> <P>// let's include the infamous windows Sample file (this time copied to c:/)<BR>FileSystemResource res = new FileSystemResource(new File("c:/Sample.jpg"));<BR>helper.addInline("identifier1234", res);</P> <P>// if you would need to include the file as an attachment, use<BR>// addAttachment() methods on the MimeMessageHelper</P> <P>sender.send(message);<BR>   <BR>Inline resources are added to the mime message using the Content-ID specified as you've seen just now (identifier1234 in this case). The order in which you're adding the text and the resource are VERY important. First add the text and after that the resources. If you're doing it the other way around, it won't work! </P> <P> </P><img src ="http://www.aygfsteel.com/javaora/aggbug/8386.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/javaora/" target="_blank">java世界畅谈</a> 2005-07-25 11:32 <a href="http://www.aygfsteel.com/javaora/archive/2005/07/25/8386.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用MethodInvokingJobDetailFactoryBeanhttp://www.aygfsteel.com/javaora/archive/2005/07/22/8176.htmljava世界畅谈java世界畅谈Fri, 22 Jul 2005 03:23:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/22/8176.htmlhttp://www.aygfsteel.com/javaora/comments/8176.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/22/8176.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/8176.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/8176.htmlUsing the MethodInvokingJobDetailFactoryBean
使用MethodInvokingJobDetailFactoryBean
Often you just need to invoke a method on a specific object. Using the MethodInvokingJobDetailFactoryBean you can do exactly this:
¾lå¸¸åœŽÍ¼Œä½ ä»…仅需要调用一个对象的一个方法。ä‹É用MethodInvokingJobDetailFactoryBean,你可以正¼‹®åœ°˜q™æ ·åšï¼š

<bean id="methodInvokingJobDetail"
  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject"><ref bean="exampleBusinessObject"/></property>
    <property name="targetMethod"><value>doIt</value></property>
</bean>


The above example will result in the doIt being called on the exampleBusinessObject (see below):


public class BusinessObject {
 
  // properties and collaborators
 
  public void doIt() {
    // do the actual work
  }
}
   

<bean id="exampleBusinessObject" class="examples.ExampleBusinessObject"/>
   
Using the MethodInvokingJobDetailFactoryBean you don't need to create one-line jobs that just invoke a method, and you only need to create the actual business object and wire up the detail object.
使用MethodInvokingJobDetailFactoryBean 你不需要创å»ÞZ¸€ä¸ªåœ¨¾U¿çš„jobsåQŒä»…仅调用它的方法,你可以仅仅只需要创å»ÞZ¸€ä¸ªå®žé™…的逻辑对象òq¶ä¸”把它¾l‘定到细节对象ã€?/P>

By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail objects implement the Stateful interface, this won't happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.

¾~ºçœåœŽÍ¼ŒQuartz jobs是无状态的åQŒåœ¨jobsçš„å¯èƒ½æ€§ä½œä¸ºç»“æžœåª„å“å½¼æ­¤ã€‚å¦‚æžœä½ é™å®šä¸¤ä¸ªè§¦å‘å™¨äØ“åŒä¸€ä¸ªJohDetail,它在½W¬ä¸€ä¸ªjob已经完成时是可能的,½W¬äºŒä¸ªå°†ä¼šå¼€å§‹ã€‚如果JobDetail实现了状态接口,它将不会发生ã€?BR><bean id="methodInvokingJobDetail"
  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject"><ref bean="exampleBusinessObject"/></property>
    <property name="targetMethod"><value>doIt</value></property>
    <property name="concurrent"><value>false</value></property>
</bean>
   
Note: By default, jobs will run in a concurrent fashion.

 



]]>
Spring--½Ž€å•ä‹É用quartz实现定时作业 http://www.aygfsteel.com/javaora/archive/2005/07/20/8070.htmljava世界畅谈java世界畅谈Wed, 20 Jul 2005 13:37:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/20/8070.htmlhttp://www.aygfsteel.com/javaora/comments/8070.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/20/8070.html#Feedback22http://www.aygfsteel.com/javaora/comments/commentRss/8070.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/8070.html    而在Spring里,已经很好的集成了QuartzåQŒç®€å•到像配cronä¸€æ øP¼Œåœ¨xmlæ–‡äšg里面配一下时间就可以自动执行åQŒä¸éœ€è¦å†™ä¸€è¡Œä»£ç ã€‚Spring对Quartz大刀阔斧的简化堪¿U°èŒƒä¾‹ï¼ŒQuartz™å¹ç›®¾l„也许可以学习一下ã€?/P>
    <bean id="methodInvokingJobDetail"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject"><ref bean="financeDAO"/></property>
        <property name="targetMethod"><value>confirmOrder</value></property>
    </bean>

    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="methodInvokingJobDetail"/>
        </property>
        <property name="cronExpression">
            <value>0 0 6,12,20 * * ?</value>
        </property>
    </bean>
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list><ref local="cronTrigger"/></list>
        </property>
    </bean>

上面˜q™æ®µé…ç½®æ–‡äšg规定了在早上6点和晚上8ç‚ÒŽ‰§è¡ŒfinanceDAO对象的confirmOrder()æ–ÒŽ³•.


附:cronExpression配置说明

字段   允许å€?/TH>   允许的特ŒDŠå­—½W?/TH>
¿U?/CODE>   0-59   , - * /
åˆ?/CODE>   0-59   , - * /
ž®æ—¶   0-23   , - * /
日期   1-31   , - * ? / L W C
月䆾   1-12 æˆ–è€?JAN-DEC   , - * /
星期   1-7 æˆ–è€?SUN-SAT   , - * ? / L C #
òqß_¼ˆå¯é€‰ï¼‰   留空, 1970-2099   , - * /



]]>
TriggerListeners and JobListenershttp://www.aygfsteel.com/javaora/archive/2005/07/20/8069.htmljava世界畅谈java世界畅谈Wed, 20 Jul 2005 13:27:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/20/8069.htmlhttp://www.aygfsteel.com/javaora/comments/8069.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/20/8069.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/8069.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/8069.htmlTriggerListeners and JobListeners
Listeners are objects that you create to perform actions based on events occuring within the scheduler. As you can probably guess, TriggerListeners receive events related to trigger,and JobListners receive events related to jobs.

Trigger-related events include: trigger firings,trigger mis-firings(discussed in the "Triggers" sections of this document),and trigger completions (the jobs fired off by the trigger is finished).

To create a listener,simply create an object the implements either the org.quartz.TriggerListener and/or org.quartz.JobListener interface. Listeners are then registered with the scheduler during run time ,and must be given a name(or rather ,they must advertise their own name via their getName()method.  Listeners can be registered as either "global" or "non-global". Global listeners receive events for ALL triggers/jobs, and non-global listeners receive events only for the specific triggers/jobs that explicitely name the listener in their getTriggerListenerNames() or getJobListenerNames() properties.

 scheduler.addGlobalJobListener(myJobListener);
or
 scheudler.addJobListener(myJobListener);
 
Listeners are not used by most users of Quartz,but are handy when application requirements create the need for the notification of events,without the Job itself explicitly nofifying the application.



]]>
更多关于CronTriggerhttp://www.aygfsteel.com/javaora/archive/2005/07/20/8046.htmljava世界畅谈java世界畅谈Wed, 20 Jul 2005 07:25:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/20/8046.htmlhttp://www.aygfsteel.com/javaora/comments/8046.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/20/8046.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/8046.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/8046.htmlMore About CronTrigger
更多关于CronTrigger

CronTriggers are often more useful than SimpleTrigger, if you need a job-firing schedule that recurs based on calendar-like notions, rather than on the exactly specified intervals of SimpleTrigger.
CronTriggers 比SimpleTrigger¾lå¸¸æ›´åŠ æœ‰ç”¨,如果你需要一个基于像日历概念的重å¤?job-firing 调度åQŒè€Œä¸æ˜¯åœ¨ä¸€ä¸ªSimpleTrigger特定的间隔ã€?/P>

With CronTrigger, you can specify firing-schedules such as "every Friday at noon", or "every weekday and 9:30 am", or even "every 5 minutes between 9:00 am and 10:00 am on every Monday, Wednesday and Friday".
使用CronTrigger,你可以限定firing-schedulers例如 “每天中午“,或者”,”每天周日上å?:30“,或者甚è‡?“每5分钟在上å?åQ?0 åˆ?10åQ?0 每周一、周三、周五â€?/P>

Cron Expressions
Cron 表达�/P>

Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of six sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent:
Cron 表达式被用来注册CronTrigger实例的。Cron表达式是字符ä¸ÔŒ¼Œå®ƒç”±å…­ä¸ªå­è¡¨è¾‘Ö¼¾l„成åQŒå®ƒæè¿°äº†ä¸åŒçš„调度¾l†èŠ‚ã€‚è¿™äº›å­è¡¨è¾¾å¼è¢«ç™½è‰²è¡¨è¾¾å¼éš”å¼€åQŒè¡¨çŽŽÍ¼š

Seconds  ¿U?BR>Minutes  åˆ?BR>Hours    æ—?BR>Day-of-Month  æ—?BR>Month         æœ?BR>Day-of-Week   å‘?/P>

An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm".
一个完整的Cron 表达式例子是字符东y€? 0 12 ? * WEBâ€?意味着每周三上å?2åQ?0ã€?/P>

Individual sub-expressions can contain ranges and/or lists. For example, the day of week field in the previous (which reads "WED") example could be replaces with "MON-FRI", "MON, WED, FRI", or even "MON-WED,SAT".
单独的子表达式可以包含åã^行的 å’?或。例如,在上一个例子一周的一天字ŒDµï¼ˆå®ƒè¯»ä½?WED"åQ‰å¯ä»¥è¢«â€œMON-FRIâ€?"MON,WED,FRI"åQŒæˆ–者甚è‡?MON-WED,SAT"替换掉ã€?/P>

Wild-cards (the '*' character) can be used to say "every" possible value of this field. Therefore the '*' character in the "Month" field of the previous example simply means "every month". A '*' in the Day-Of-Week field would obviously mean "every day of the week".
¾lŸé…½W¦ï¼ˆ"*"字符åQ‰å¯ä»¥è¢«ç”¨æ¥ä½œäØ“˜q™ä¸ªå­—段çš?每一ä¸?可能倹{€‚所ä»?在上一个例子月字段中的"*"字符表示每个月ã€?一ä¸?*"在周天将明显意味着周的每一天ã€?/P>

All of the fields have a set of valid values that can be specified. These values should be fairly obvious - such as the numbers 0 to 59 for seconds and minutes, and the values 0 to 23 for hours. Day-of-Month can be any value 0-31, but you need to be careful about how many days are in a given month! Months can be specified as values between 0 and 11, or by using the strings JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. Days-of-Week can be specified as vaules between 1 and 7 (1 = Sunday) or by using the strings SUN, MON, TUE, WED, THU, FRI and SAT.
所有字ŒDµéƒ½ç”¨ä¸€ä¸ªåˆæ³•限定的倹{€‚这些值应该是明显的,例如0åˆ?9数字为秒和分的限定,0åˆ?3为小时。月的某天可以是0-31的,或者你需要消息给个月有多ž®‘天åQæœˆä»½å¯ä»¥è¢«é™å®šåœ?åˆ?1åQŒæˆ–è€…ï¼Œä½¿ç”¨è‹±æ–‡å­—ç¬¦ä¸²ç¾ƒå†™ã€‚ä¸€ä¸ªç¤¼æ‹œçš„ä¸€å¤©å¯ä»¥è¢«é™å®šä½œäØ“1åˆ?åQ?=SunndayåQ‰æˆ–者ä‹É用英文字½W¦ä¸²ã€?/P>


The '/' character can be used to specify increments to values. For example, if you put '0/15' in the Minutes field, it means 'every 15 minutes, starting at minute zero'. If you used '3/20' in the Minutes field, it would mean 'every 20 minutes during the hour, starting at minute three' - or in other words it is the same as specifying '3,23,43' in the Minutes field.
"/"字符可以内用来限定值的增加。例如,如果你将'0/15'攑ֈ°åˆ†é’Ÿå­—段åQŒå®ƒæ„å‘³ç€"æ¯?5分钟åQŒå¼€å§‹äºŽ0分钟"。如果你使用"3/20"在分钟字ŒDµä¸­åQŒä½ ž®†æ„å‘³ç€"一个小时内æ¯?0分钟åQŒå¼€å§‹äºŽ3分钟"---  或者换­a€ä¹‹ï¼Œå®ƒå’Œåœ¨åˆ†é’Ÿå­—ŒD?3,23,43"限定是一æ ïLš„ã€?/P>


The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify "no specific value". This is useful when you need to specify something in one of the two fields, but not the other. See the examples below (and CronTrigger JavaDOC) for clarification.

"?"å­—ç¬¦æ˜¯å…è®æ€Ø“月的某一天或者周的某一天字ŒD늚„。它被用来限å®?没有限定å€?。这是有用的åQŒå½“你需要限定一些事情在一个或两个字段中,但不是这里的ã€?/P>

The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" or "FRIL" both mean "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.

"L"字符是允许用来月某天和周某天字段。这个字½W¦æ˜¯ä¸€ä¸?last"的羃写,但是它有不同的意义在两个字段的其中之一。例如,˜q™ä¸ªå€?L"在月字段的某一天意味着" ˜q™ä¸ªæœˆçš„æœ€åŽä¸€å¤?åQ?1或è€?8½{‰ç­‰ã€?/P>

Here are a few more examples of expressions and their meanings - you can find even more in the JavaDOC for CronTrigger

CronTrigger Example 1 - an expression to create a trigger that simply fires every 5 minutes

  "0 0/5 * * * ?"

CronTrigger Example 2 - an expression to create a trigger that fires every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.).

  "10 0/5 * * * ?"

CronTrigger Example 3 - an expression to create a trigger that fires at 10:30, 11:30, 12:30, and 13:30, on every Wednesday and Friday.

  "0 30 10-13 ? * WED,FRI"

CronTrigger Example 4 - an expression to create a trigger that fires every half hour between the hours of 8 am and 10 am on the 5th and 20th of every month. Note that the trigger will NOT fire at 10:00 am, just at 8:00, 8:30, 9:00 and 9:30

  "0 0/30 8-9 5,20 * ?"

Note that some scheduling requirements are too complicated to express with a single trigger - such as "every 5 minutes between 9:00 am and 10:00 am, and every 20 minutes between 1:00 pm and 10:00 pm". The solution in this scenario is to simply create two triggers, and register both of them to run the same job.



]]>
What is Quartz? (什么是Quartz?)http://www.aygfsteel.com/javaora/archive/2005/07/20/8036.htmljava世界畅谈java世界畅谈Wed, 20 Jul 2005 04:05:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/20/8036.htmlhttp://www.aygfsteel.com/javaora/comments/8036.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/20/8036.html#Feedback1http://www.aygfsteel.com/javaora/comments/commentRss/8036.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/8036.htmlWhat is Quartz? (什么是Quartz?)
Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components or EJBs. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.

Quartz 是一个功能齐全的、开源的jobæ—‰™—´è°ƒåº¦¾pȝ»ŸåQŒå®ƒå¯ä»¥è¢«ç»“合的,或者伴随虚拟的ä»ÖM½•J2EE或J2SE½E‹åº-从最ž®çš„独立的应用程序到最大的e-commerce¾pȝ»Ÿè¢«ä‹É用。Quartz可以用来创徏½Ž€å•或复杂的时间调度来执行十、百、千、甚至上万的jobs;获得的jobè¢«å®šä¹‰äØ“ä¸€ä¸ªæ ‡å‡†çš„java¾l„äšg或EJBs. ˜q™ä¸ªQuartz æ—‰™—´è°ƒåº¦åŒ…含很多企业¾cȝš„特征åQŒä¾‹å¦‚JTA事务和簇ã€?/P>

The licensing of Quartz versions 1.0 through 1.4.5 is similar to both the BSD and ASF (Apache) public licenses, which means it's free for use, even within commercial products.

Quartz 1.0版本åˆ?.4.5版本的licensing 是类ä¼ég¸ŽBSDå’ŒASF(apache)公共licenses, 它意味着可以免费使用åQŒç”šè‡³ä‹É用在商业产品中ä‹É用ã€?BR>With the upcoming release of version 1.5.0, Quartz is moving to the Apache 2.0 license.
伴随1.5.0版本的发布,Quartzž®†è{¿UÕd‘apache 2.0 çš„license.

What can Quartz do for you? (Quartz可以ä¸ÞZ½ åšä»€ä¹ˆï¼Ÿ)
If your application has tasks that need to occur at given moments in time, or if your system has recurring maintenance jobs then Quartz may be your ideal solution.

如果你的½E‹åºæœ‰ä¸€äº›è¿™æ ïLš„ä»ÕdŠ¡åQŒå®ƒéœ€è¦åŠæ—¶åœ°å‘生在给定时é—ß_¼Œæˆ–者你如果你的¾pȝ»Ÿæœ‰è¿ž¾l­ç»´æŠ¤jobsåQŒé‚£ä¹ˆQuartzå¯ä»¥æˆäØ“ä½ çš„ç†æƒ³çš„è§£å†Ïx–¹æ¡ˆã€?/P>

Sample uses of job scheduling with Quartz:
Quartz使用jobæ—‰™—´è°ƒåº¦çš„范ä¾?/P>

Driving Workflow: As a new order is initially placed, schedule a Job to fire in exactly 2 hours, that will check the status of that order, and trigger a warning notification if an order confirmation message has not yet been received for the order, as well as changing the order's status to 'awaiting intervention'.
System Maintenance: Schedule a job to dump the contents of a database into an XML file every business day (all weekdays except holidays) at 11:30 PM.

工作‹¹é©±åŠ¨ï¼šä½œäØ“ä¸€ä¸ªæ–°çš„è®¢å•è¢«åˆå§‹åŒ–æ”¾¾|®ï¼Œè°ƒåº¦ä¸€ä¸ªjobåŽÕd·¥ä½œåœ¨æ­£å¥½ä¸¤ä¸ªž®æ—¶å†…,它将‹‚€æŸ¥è®¢å•的状态,òq¶ä¸”触发一个警告通知如果订单¼‹®è®¤ä¿¡æ¯æ²¡æœ‰è¢«æŽ¥æ”Óž¼Œåˆæ”¹å˜è®¢å•的状态到"½{‰å¾…òq²æ¶‰"ã€?BR>¾pȝ»Ÿ¾l´æŠ¤åQšè°ƒåº¦ä¸€ä¸ªjob来将数据库è{åŒ–äØ“XMLæ–‡äšg 每商业日期(所有周末除了节假日åQ‰åœ¨ä¸‹åˆ11åQ?0ã€?/P>

 



]]>
Using the ProxyFactoryBean to create AOP proxieshttp://www.aygfsteel.com/javaora/archive/2005/07/07/7249.htmljava世界畅谈java世界畅谈Thu, 07 Jul 2005 02:43:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/07/07/7249.htmlhttp://www.aygfsteel.com/javaora/comments/7249.htmlhttp://www.aygfsteel.com/javaora/archive/2005/07/07/7249.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/7249.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/7249.htmlUsing the ProxyFactoryBean to create AOP proxies
If you're using the Spring Ioc container (an applicationContext or BeanFactory) for you business object--and you should be!-- you will want to use one of Spring's AOP fatoryBeans.(Remeber that a factory bean introduces a layer of indirection, enabling it to create objects of different type).

The basic way to create an AOP proxy in Spring to use the org.springframework.aop.framework.ProxyFactoryBean. This gives complete control over the pointcuts an advice that will apply, and theire ordering . However ,there are simpler options that are preferable(更可取的、更好的) if you don't need such control.

Basics
The proxyFactoryBean,like other Spring FactoryBean implementations,introduces a level of indirection(间接). If you define a ProxyFactoryBean with name foo,what objects referencing foo see is not the ProxyFactoryBean instance itself, but an object created by the ProxyFactoryBeans's implementation of the getObject() method. This method will create an AOP proxy wrapping a target object.

One of the most important benefits of using a ProxyFactoryBean or other IoC-aware to create AOP proxies, it that it means that advices and pointcuts can also be managed by IoC. This is a powerful feature , enabling certain approaches that are hard to achieve with other AOP frameworks. For example,an advice may itself reference application objects(besides the target , which should be available in any AOP framework),benefiting from all the pluggability provided by Dependency Injection.

JavaBean properties
Like most FactoryBean implementations provided with Spring, ProxyfactoryBean is itself a JavaBean. It properties are used to:
Specify the target you  want to proxy
Specify whether to use CGLIB

Some key properties are inherited from org.springframework.aop.framework.ProxyConfig: the subclass for all AOP proxy factories. These include:
proxyTargetClass: true if we should proxy the target class,rather than its interfaces. If this  is true we need to use CGLIB.

optimize: whether to apply aggressive optimization to created proxies. Don't use this setting unless you  understand how the relevant(相关çš? AOP proxy handles optimization. This is currently used only for CGLIB proxies;it has no effect with  JDK dynamic proxies(the default).

frozen:whether avice changes should be disallowed once the proxy factory has bean configured. Default is false.

exposeProxy: whether the current proxy should be exposed in a ThreadLocal so that it can be accessed by the target (It's available via the MethodInvocation without the need for a ThreadLocal) If a target needs to obtain the proxy and exposedProxy is true, the target can use the AopContext.currentProxy() method.

aopProxyFactory: the implementation of AopProxyFactory to use. Offers a way of customizing whether to use dynammic proxies,CGLIB or any other proxy strategy. The default implementation will choose dynamic proxies or CGLIB appropriately. There should be need to use this property, it's intended to allow the addition of new proxy types in spring 1.1.

Other properties specific to ProxyFactoryBean include:
.proxyInterfaces: array of String interface names.  If this isn't supplied, a CGLIB proxy for the target class will be used.
.interceptorNames:String array of Advisor,interceptor or other advice names to apply.Ordering is sugnicicant. first come,first serve that is. The first interceptor in the list will be the first to be able to interceptor the invocation (of course if it concerns a regular MethodInterceptor or BeforeAdvice. The names are bean names in the current factory , including  bean names from ancestor factories. You  can't mention bean references here since doing so would result iin the ProxyFactoryBean ignoring the singleton  setting of the advise. you can append an iinterceptor name with an asterisk(*).  This will result  in the application of all advisor beans withe names starting with the part before the asterisk to be applied.  An example of using this feature can be found below.

Singleton: whether or not the factory should return a single object, no matter how often the getObject() method is called. Server FactoryBean implementations offer such a method. Default value is true. If you want to use stateful advice --for example ,for stateful mixins-user prototype advices along withe s singleton value of false.

Proxying interfaces

<bean id="personTarget" class="com.mycompany.PersionImpl">
   <property name="name"><value>Tony</value></property>
   <property name="age"><value>51</value></property>  
</bean>

<bean id="myAdvisor" class="com.mycompany.MyAdvisor">
   <property name="someProperty"><value>Custom string property value</value></property>
</bean>

<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInteceptor" ></bean>

<bean id="person" class="org.springframework.aop.framework.ProxyFactoryBean">
   <property name="proxyInterface"><value>com.company.Person</value></property>
  
   <property name="target"><ref local="personTarget"/></property>
   <property name="interceptorNames">
      <list>
         <value>myAdvisor</value>
         <value>debugInterceptor</value>
      </list>
   </property>
</bean>

 



]]>
Spring中的 JasperReportshttp://www.aygfsteel.com/javaora/archive/2005/06/29/6863.htmljava世界畅谈java世界畅谈Wed, 29 Jun 2005 02:24:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/06/29/6863.htmlhttp://www.aygfsteel.com/javaora/comments/6863.htmlhttp://www.aygfsteel.com/javaora/archive/2005/06/29/6863.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/6863.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/6863.html13.7. JasperReports
JasperReports (http://jasperreports.sourceforge.net) is a powerful, open-source reporting engine that supports the creation of report designs using an easily understood XML file formats. JasperReports is capable of rendering reports output into four different formats: CSV, Excel, HTML and PDF.

13.7.1. Dependencies åQˆä¾èµ–)
Your application will need to include the latest release of JasperReports, which at the time of writing was 0.6.1. JasperReports itself depends on the following projects:

BeanShell

Commons BeanUtils

Commons Collections

Commons Digester

Commons Logging

iText

POI

JasperReports also requires a JAXP compliant(适应� XML parser.

13.7.2. ConfigurationåQˆé…¾|®ï¼‰
To configure JasperReports views in your ApplicationContext you have to define a ViewResolver to map view names to the appropriate view class depending on which format you want your report rendered in.

13.7.2.1. Configuring the ViewResolver
Typically, you will use the ResourceBundleViewResolver to map view names to view classes and files in a properties file

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="basename">
        <value>views</value>
    </property>
</bean>
                 
Here we've configured an instance of ResourceBundleViewResolver which will look for view mappings in the resource bundle with base name views. The exact contents of this file is described in the next section.

13.7.2.2. Configuring the Views
Spring contains five different View implementations for JasperReports four of which corresponds to one of the four output formats supported by JasperReports and one that allows for the format to be determined at runtime:

JasperReport View Class
1.JasperReportsView           CSV
2.JasperReportsHtmlView       HTML
3.JasperReportsPdfView        PDF
4.JasperReportsXlsView        EXCEL
5.JasperReportsMutiFormatView

Mapping one of these classes to a view name and a report file is simply a matter of adding the appropriate entries into the resource bundle configured in the previous section as shown here:

simpleReport.class=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
simpleReport.url=/WEB-INF/reports/DataSourceReport.jasper
             
Here you can see that the view with name, simpleReport, is mapped to the JasperReportsPdfView class. This will cause the output of this report to be rendered in PDF format. The url property of the view is set to the location of the underlying report file.


13.7.2.3. About Report Files
JasperReports has two distinct types of report file: the design file, which has a .jrxml extension, and the compiled report file, which has a .jasper extension. Typically, you use the JasperReports Ant task to compile your .jrxml design file into a .jasper file before deploying it into your application. With Spring you can map either of these files to your report file and Spring will take care of compiling the .jrxml file on the fly for you. You should note that after a .jrxml file is compiled by Spring, the compiled report is cached for the life of the application. To make changes to the file you will need to restart your application.

JasperReports拥有两种不同的类型的报表文äšgåQšè®¾è®¡æ–‡ä»Óž¼Œå®ƒæ˜¯ä¸€ä¸ªæ‹¥æœ?jrxml 扩展的文ä»Óž¼Œå’Œç¼–译好的报表文件。一般,你ä‹É用antä»ÕdŠ¡åœ¨ä½ éƒ¨çÖvåˆîC½ çš„程序中之前来编译你çš?jrxml设计报表文äšg。ä‹É用Spring 你可以媄ž®„这些文件中的ä“Q一åˆîC½ çš„æŠ¥è¡¨æ–‡ä»Óž¼ŒSpringž®†ä¼šä¸ÞZ½ åœ¨ç©ºé—²æ—¶ç…§é¡¾¾~–译.jrxmlæ–‡äšgã€?你应当注意在一ä¸?jrxmlæ–‡äšg被编译之后,˜q™ä¸ª¾~–译的报表是被缓存的在你的application生命周期中。如果这些文件修改了åQŒä½ éœ€è¦é‡æ–°å¯åŠ¨çš„ä½ çš„½E‹åºã€?/P>

13.7.2.4. Using JasperReportsMultiFormatView  使用JasperReportsMutiFormatView
The JasperReportsMultiFormatView allows for report format to be specified at runtime. The actual rendering of the report is delegated to one of the other JasperReports view classes - the JasperReportsMultiFormatView class simply adds a wrapper layer that allows for the exact implementation to be specified at runtime.

JasperReportsMutilFormatView允许你在˜qè¡Œæ—¶æœŸæŒ‡å®šæŠ¥è¡¨çš„æ ¼å¼ã€‚报表的实际的表现是为委托到JasperReports 视图¾cȝš„中的一ä¸?-JasperMutilFormatView¾cȝ®€å•的加了一个包装层允许在运行时期正¼‹®çš„实现被指定ã€?/P>

The JasperReportsMultiFormatView class introduces two concepts: the format key and the discriminator key. The JasperReportsMultiFormatView class uses the mapping key to lookup the actual view implementation class and uses the format key to lookup up the mapping key. From a coding perspective you add an entry to your model with the formay key as the key and the mapping key as the value, for example:

 

public ModelAndView handleSimpleReportMulti(HttpServletRequest request,
HttpServletResponse response) throws Exception {

  String uri = request.getRequestURI();
  String format = uri.substring(uri.lastIndexOf(".") + 1);

  Map model = getModel();
  model.put("format", format);

  return new ModelAndView("simpleReportMulti", model);
}
In this example, the mapping key is determined from the extension of the request URI and is added to the model under the default format key: format. If you wish to use a different format key then you can configure this using the formatKey property of the JasperReportsMultiFormatView class.

By default the following mapping key mappings are configured in JasperReportsMultiFormatView:
Table 13.3. JasperReportsMultiFormatView Default Mapping Key Mappings

Mapping Key View Class
csv   JasperReportsCsvView
html  JasperReportsHtmlView
pdf   JasperReportsPdfView
xls   JasperReportsXlsView

So in the example above a request to URI /foo/myReport.pdf would be mapped to the JasperReportsPdfView class. You can override the mapping key to view class mappings using the formatMappings property of JasperReportsMultiFormatView.



]]>
Remoting using Springhttp://www.aygfsteel.com/javaora/archive/2005/06/24/6656.htmljava世界畅谈java世界畅谈Fri, 24 Jun 2005 02:15:00 GMThttp://www.aygfsteel.com/javaora/archive/2005/06/24/6656.htmlhttp://www.aygfsteel.com/javaora/comments/6656.htmlhttp://www.aygfsteel.com/javaora/archive/2005/06/24/6656.html#Feedback0http://www.aygfsteel.com/javaora/comments/commentRss/6656.htmlhttp://www.aygfsteel.com/javaora/services/trackbacks/6656.htmlConsiderations when choosing a technology åQˆå½“选择一个技术时候的考虑åQ?BR>Each and every technology presented here has its drawbacks. You should carefully consider you needs, the services your exposing and the objects you'll be sending over the wire when choosing a technology.
每个技术这里介¾lçš„都有它的¾~ºç‚¹ã€‚你应该仔细考虑你的需要,当你选择的时考虑你的暴露的服务和你将要发送关¾pȝš„对象ã€?/P>


When using RMI, it's not possible to access the objects through the HTTP protocol, unless you're tunneling the RMI traffic. RMI is a fairly heavy-weight protocol in that it support full-object serialization which is important when using a complex data model that needs serialization over the wire. However, RMI-JRMP is tied to Java clients: It is a Java-to-Java remoting solution.
当我们ä‹É用RMIåQŒæˆ‘们不可以通过http协议讉K—®å¯¹è±¡åQŒé™¤éžä½ æ‰“通RMI交通的隧道。RMI 是一个非帔R‡é‡çñ”协议åQŒåœ¨å…¶ä¸­ä»–支持的所有对象的序列化是非常重要的,当ä‹É用一个需要序列化兌™”的复杂的数据模型。然而,RMI-JRMP 是依赖java客户端的åQšå®ƒæ˜¯java-to-java的远½E‹è§£å†Ïx–¹æ¡ˆã€?/P>


Spring's HTTP invoker is a good choice if you need HTTP-based remoting but also rely on Java serialization. It shares the basic infrastructure with RMI invokers, just using HTTP as transport. Note that HTTP invokers are not only limited to Java-to-Java remoting but also to Spring on both the client and server side. (The latter also applies to Spring's RMI invoker for non-RMI interfaces.)
Spring çš„HTTP invoker 是一个不错的选择åQŒå¦‚果你需要基于HTTP的远½E‹ï¼Œè€Œä¸”需要java序列化回复。它使用RMI invoker分äín了基¼‹€¾l“æž„åQŒä»…ä»…ä‹É用HTTPä½œäØ“ä¼ è¾“ã€‚æ³¨æ„HTTP invoker不是仅仅限制¾l™java-to-java的远½E‹è€Œä¸”是在客户端和服务器端的Spring.(后面的也应用到Spring çš„RMI invoker为非RMI的接å?ã€?/P>

Hessian and/or Burlap might provide significant value when operating in a heterogeneous environment, because they explicitly allow for non-Java clients. However, non-Java support is still limited. Known problems include the serialization of Hibernate objects in combination with lazily initializing collections. If you have such a data model, consider using RMI or HTTP invokers instead of Hessian.
Hessian 和或 Burlap可以支持重要的å€û|¼Œå½“在一个异质的环境操作åQŒå› ä¸ÞZ»–们明¼‹®çš„允许为非java 对象。然而非java对象是受限制的,知道的问题包括hibernate对象序列化与懒汉初始化集合的¾l“合上。如果你有这æ ïLš„æ•°æ®æ¨¡åž‹åQŒè€ƒè™‘使用RMI或HTTP invokers而不是Hessioan.

JMS can be useful for providing clusters of services and allowing the JMS broker to take care of load balancing, discovery and auto-failover. By default Java serialization is used when using JMS remoting but the JMS provider could use a different mechanism for the wire formatting, such as XStream to allow servers to be implemented in other technologies.


Last but not least, EJB has an advantage over RMI in that it supports standard role-based authentication and authorization and remote transaction propagation. It is possible to get RMI invokers or HTTP invokers to support security context propagation as well, although this is not provided by core Spring: There are just appropriate hooks for plugging in third-party or custom solutions here.

 



]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ×óÈ¨ÏØ| ½¶ÁëÏØ| ¼ÎÒåÏØ| ÐËÒµÏØ| °¢ºÏÆæÏØ| íìíôÏØ| ӥ̶ÊÐ| ¿ËÀ­ÂêÒÀÊÐ| ËÉÌÒ| ´ó¹ØÏØ| ÎåÔ­ÏØ| ¶î¶û¹ÅÄÉÊÐ| ½ðƽ| ÍÍÃÅÇø| °¢À­ÉÆÃË| ÔúêãÌØÆì| ½­ÓÍÊÐ| ÓÀ²ýÏØ| ÂíÁúÏØ| ·ð¸ÔÏØ| »¨Ô«ÏØ| ÖêÖÞÊÐ| µÂÇåÏØ| ±¦É½Çø| ¿Æ¼¼| ¶Ø»¯ÊÐ| ÐÐÌÆÏØ| ¸ö¾ÉÊÐ| ÄÏ¿µÊÐ| ÁÙÏÄÊÐ| Íû½­ÏØ| ºôͼ±ÚÏØ| ÃñÈ¨ÏØ| ÎÚÀ­ÌØÖÐÆì| Íû¿üÏØ| ¸»Ë³ÏØ| ÈýºÓÊÐ| ÁéÉ½ÏØ| Ìì×£| ´ó·áÊÐ| °²ÇìÊÐ|