Spring调用RMI
RMI(Remote Method Invocation) 远程方法调用,实现JAVA应用之间的远程通信。下面介绍使用Spring如何使用RMI。
包的结构如下:
定义调用接口
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.xmlpublic 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.编写配置文件
4.关于cronExpression表达式
2/5 44-46 22,23 9 9 ? 2012