Java Reference
In-Depth Information
Now you can operate the remote MBean through this proxy as if it were a local bean. The preceding
MBean operations invoked on the MBean server connection directly can be simplified as follows:
package com.apress.springenterpriserecipes.replicator;
...
public class Client {
public static void main(String[] args) throws Exception {
...
FileReplicator fileReplicatorProxy =
(FileReplicator) context.getBean("fileReplicatorProxy");
String srcDir = fileReplicatorProxy.getSrcDir();
fileReplicatorProxy.setDestDir(srcDir + "_1");
fileReplicatorProxy.replicate();
}
}
6-4. Sending E-mail with Spring's E-mail Support
Problem
Many applications need to send e-mail. In a Java application, you can send e-mail with the JavaMail API.
However, when using JavaMail, you have to handle the JavaMail-specific mail sessions and exceptions.
As a result, your application becomes JavaMail dependent and hard to switch to another e-mail API.
Solution
Spring's e-mail support makes it easier to send e-mail by providing an abstract and implementation-
independent API for sending e-mail. The core interface of Spring's e-mail support is MailSender .
The JavaMailSender interface is a subinterface of MailSender that includes specialized JavaMail
features such as Multipurpose Internet Mail Extensions (MIME) message support. To send an e-mail
message with HTML content, inline images, or attachments, you have to send it as a MIME message.
How It Works
Suppose that you want your file replicator application to notify the administrator of any error. First, you
create the following ErrorNotifier interface, which includes a method for notifying of a file copy error:
package com.apress.springenterpriserecipes.replicator;
public interface ErrorNotifier {
public void notifyCopyError(String srcDir, String destDir, String filename);
}
 
Search WWH ::




Custom Search