Springframework (6)

zhaozj2021-02-16  87

Second, Spring Integration

1, Mail

(1) SimpleMailMessage

l Create a message

SimpleMailMersage Msg = new SimpleMailMAESSAGE ();

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");

(2) Mailsender

l Defining a message sender

Class = "Org.springframework.mail.javamail.javamailsenderImpl">

smtp.mail.org

Joe

abc123

l Send a message

Mailsender Sender = (Mailsender) CTX.getBean ("Mailsender");

Sender.send (MSG);

2, Scheduling

(1) Scheduler

l Built-in support:

Ø Java 2 Timer: Timer, Timertask

Ø Quartz: Schedules, JobDetails, Triggers

(2) ScheduledTimertask

l We want to run the task

Public class mytask eXtends timertask {

Public void run () {

// do something

}

}

Class = "... scheduling.timer.scheduledtimertask">

60000

1000

Packaging Java.util.Timertask Scheduling Bean

(3) TimerFactoryBean

l Create a scheduler

Class = "... Scheduling.Timer.timerFactoryBean">

Create a java.util.timer object

l When you created bean, Timer started running

3, JNDI

(1) JNDITEMPLATE

l Using JNDITEMPLATE

Properties P = new profment ();

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) {

...

}

(2) JNDIOBJECTFACRORYBEAN

l Use beans to replace loopup

Class = "org.springframework.jndi.jndItemplate">

jnp: // localhost: 1099

Class = "org.springframework.jndi.jndiObjectFactoryBean">

Something

Object o = ctx.getbean ("something");

转载请注明原文地址:https://www.9cbs.com/read-10470.html

New Post(0)