SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("me@mail.org");
msg.setTo("you@mail.org");
msg.setCc(new String[] {"he@mail.org", "she@mail.org"});
msg.setBcc(new String[] {"us@mail.org", "them@mail.org"});
msg.setSubject("my subject");
msg.setText("my text");
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host"><value>smtp.mail.org</value></property>
<property name="username"><value>joe</value></property>
<property name="password"><value>abc123</value></property>
</bean>
MailSender sender = (MailSender) ctx.getBean("mailSender");
sender.send(msg);
public class MyTask extends TimerTask {
public void run() {
// do something
}
}
<bean id="myTask"
class="...scheduling.timer.ScheduledTimerTask">
<property name="timerTask">
<bean class="eg.MyTask"/>
</property>
<property name="delay"><value>60000</value></property>
<property name="period"><value>1000</value></property>
</bean>
<bean id="scheduler"
class="...scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list><ref bean="myTask"/></list>
</property>
</bean>
Properties p = new Properties();
p.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.provider.url",
"jnp://localhost:1099");
JndiTemplate jndi = new JndiTemplate(p);
Properties env = jndi.getEnvironment();
try {
jndi.bind("Something", something);
Object o = jndi.lookup("Something");
jndi.unbind("Something");
}
catch(NamingException e) {
...
}
<bean id="jndiTemplate"
class="org.springframework.jndi.JndiTemplate">
<constructor-arg>
<props>
<prop key="java.naming.factory.initial">
org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
</props>
</constructor-arg>
</bean>
<bean id="something"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"><ref bean="jndiTemplate"/></property>
<property name="jndiName"><value>Something</value></property> </bean>
Object o = ctx.getBean("something"); |
|
來自: web.anywhere > 《我的圖書館》
联系客服
微信扫码,添加客服企业微信
客服QQ:
1732698931联系电话:4000-999-276
客服工作时间9:00-18:00,晚上非工作时间,请在微信或QQ留言,第二天客服上班后会立即联系您。