By default, the JtaTransactionManager will attempt to automatically detect a UserTransaction bound to the java:comp/UserTransaction JNDI name; if the java:comp/UserTransaction object also implements the TransactionManager, the JtaTransactionManager will use that; if the java:comp/ UserTransaction does not implement the TransactionManager, the JtaTransactionManager will attempt to find the TransactionManager under these JNDI names:
• java:comp/UserTransaction: The default JNDI name, used by Resin 2.x, Oracle OC4J (Orion),
JOnAS (JOTM), BEA WebLogic, and IBM WebSphere
• java:pm/TransactionManager: JNDI name for TransactionManager in Borland Enterprise Server and Sun Application Server (Sun ONE 7 and later)
• java:comp/TransactionManager: JNDI name used in Resin 3.x
• java:/TransactionManager: The name used in the JBoss Application Server
@Controller Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features Spring will use any class annotated with the @Controller annotation as a Controller in Spring MVC support.
/** * * @author NathA1 Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features Spring will use any class annotated with the @Controller annotation as a Controller in Spring MVC support. */
@Controller /** The @RequestMapping annotation is used to map URLs to the Controller class or aparticular method If you want to use the @RequestMapping annotation at the method level, you need to configure DefaultAnnotationHandlerMapping. This is done by default for DispatcherServlet, but if you are implementing your own handler adapter, you will have to define AnnotationMethodHandlerAdapter
Job Scheduling with Spring Scheduling support in Spring comes in two distinct forms: JDK Timer-based and Quartz-based. The JDK Timer-based approach provides scheduling capabilities on any version 1.3 or later JVM, and it does not need external dependencies beyond Spring. Timer-based scheduling is quite primitive and provides limited flexibility when defining job schedules. However, Timer support is included with Java and requires no external libraries, which might be beneficial if you are restricted by application size or corporate policy. Quartz-based scheduling is much more flexible and allows triggers to be defined in a much more real-world way, such as the earlier example of 3:00 p.m. every Monday, Wednesday, and Friday
Scheduling Jobs Using JDK Timer Creating a Simple Job To create a job to use with the Timer class, you simply extend the TimerTask class and implement the run() method to execute your job’s logic
public class HelloWorldTask extends TimerTask { public void run() { System.out.println("Hello World!"); } }
import java.util.Timer; public class OneOffScheduling { public static void main(String[] args) { Timer t = new Timer(); t.schedule(new HelloWorldTask(), 1000); } }
============================================= Scheduling a Repeating Task public class FixedDelayScheduling { public static void main(String[] args) throws Exception{ Timer t = new Timer(); t.schedule(new HelloWorldTask(), 1000, 3000); } }
import java.util.Timer; public class FixedRateScheduling { public static void main(String[] args) throws Exception { Timer t = new Timer(); t.scheduleAtFixedRate(new HelloWorldTask(), 1000, 1000); } } ===================================== Spring Support for JDK Timer Scheduling The core of Spring’s Timer support comes in the form of the ScheduledTimerTask and TimerFactoryBean classes. The ScheduledTimerTask class acts as a wrapper around your TimerTask implementations and allows you to define trigger information for the job. Using the TimerFactoryBean, you can have Spring automatically create Timer instances for a given list of ScheduledTimerTask beans using the trigger configuration data when creating the trigger
================================= Scheduling Jobs Using OpenSymphony Quartz Quartz provides a huge range of features such as persistent jobs, clustering, and distributed transaction,The core of Quartz is made up of two interfaces, Job and Scheduler, and two classes, JobDetail and Trigger
Scheduling jobs using Quartz or Timer Dynamic Job Scheduling using Spring Scheduling Jobs Using OpenSymphony Quartz
============================================================= ================================================================================================================================== public class SpringBeanInterceptors extends SpringBeanAutowiringInterceptor {
============================================================= public class Bar {
@Override public String toString() { return getClass().getName(); } } ================================================================================================================================== public class Foo {
@Override public String toString() { return getClass().getName(); } }