Java的Spring框架下RMI与quartz的调用方法

Spring调用RMI
RMI(Remote Method Invocation) 远程方法调用,实现JAVA应用之间的远程通信。下面介绍使用Spring如何使用RMI。

包的结构如下:

Java的Spring框架下RMI与quartz的调用方法_第1张图片

定义调用接口

public interface UserDao {

  public String getUser(String username)throws Exception;

}

接口实现类

public class UserDaoImplimplements UserDao {

  public String getUser(Stringusername)throws Exception {

    return"test:"+username;

  }

}

(1)配置RMI服务:

applicationContext-rmi-server.xml

  

  

    

    

    

    

  

(2)启动RMI服务:

public class RmiServer {

  publicstaticfinal ApplicationContextcontext =new ClassPathXmlApplicationContext("applicationContext-rmi-server.xml");

  publicstaticvoid main(String[] args) {

  }

}

(3)访问RMI服务

applicationContext-rmi-client.xml

  

    

    

    

    

  

 

public class RmiClient {

  publicstaticvoid main(String[] args) {

    ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext-rmi-client.xml");

    UserDao userDao = (UserDao)context.getBean("userDaoImpl_client");

    if(userDao !=null){

      try {

       System.out.println(userDao.getUser("li"));

      } catch (Exception e) {

       e.printStackTrace();

      }

    }

  }

}

spring调用quartz
1.quartz是一个作业调度框架,spring集成的quartz,使用非常方便。

2.编写执行类

import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
 
public class QuartzTest { 
 
 public static void main(String[] args) { 
 System.out.println("Test start."); 
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-quartz.xml"); 
    //如果配置文件中将startQuertz bean的lazy-init设置为false 则不用实例化 
    //context.getBean("startQuertz"); 
    System.out.print("Test end.."); 
 } 
 
} 

3.编写配置文件

 
 
 
   
 
  
  
 
 
 
   
     
       
     
     
     
     2/5 44-46 22,23 9 9 ? 2012 
      
           
   
   
   
   
     
       
         
       
     
    

4.关于cronExpression表达式

  
 2/5 44-46 22,23 9 9 ? 2012 
 

你可能感兴趣的:(Java的Spring框架下RMI与quartz的调用方法)