标签:
1 public MyFtpServer() throws FtpException{ 2 3 //读取my-ftpd-full.xml,连接数据库和监控配置,然后来启动server 4 FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(xmlPath); 5 FtpServer server = null; 6 if (ctx.containsBean("server")) { 7 server = (FtpServer)ctx.getBean("server"); 8 } else { 9 String[] beanNames = ctx.getBeanNamesForType(FtpServer.class); 10 if (beanNames.length == 1) { 11 server = (FtpServer)ctx.getBean(beanNames[0]); 12 } else if (beanNames.length > 1) { 13 logger.info("Using the first server defined in the configuration, named " + beanNames[0]); 14 server = (FtpServer)ctx.getBean(beanNames[0]); 15 } else { 16 logger.info("XML configuration does not contain a server configuration"); 17 } 18 } 19 20 //ftp服务器启动 21 server.start(); 22 23 //在jvm关闭的时候,清理函数 24 addShutdownHook(server); 25 } 26 27 /** 28 * 清理的垃圾的钩子函数 29 * @param engine 30 */ 31 private void addShutdownHook(final FtpServer engine) 32 { 33 Runnable shutdownHook = new Runnable() { 34 public void run() { 35 logger.info("Stopping server..."); 36 engine.stop(); 37 } 38 }; 39 Runtime runtime = Runtime.getRuntime(); 40 runtime.addShutdownHook(new Thread(shutdownHook)); 41 }
<ftplets> <ftplet name="MyFtplet"> <beans:bean class="com.shiyi.km.ftpserver.control.MyFtplet"> <!-- <beans:property name="foo" value="123" /> --> </beans:bean> </ftplet> </ftplets>
标签:
原文地址:http://www.cnblogs.com/chenkaideng/p/4886018.html