Brad Sisk Wrote:

>I appreciate your suggestion, Ralph. But if I'm not mistaken, it looks
>like you've posted a solution for a standalone Java app-not the Spring
>approach to bean instantiation. For example, your solution directly
>instantiates FtpServer the way a main() method would-rather than using
>the Spring BeanFactory or ApplicationContext approach.

>As I originally posted, I already know how to launch FTPServer using
>Java. That's not what I'm asking about. My question was about how one
>does the same thing in a deployed Spring application. Spring.  In
>Spring, you are not supposed to directly instantiate any object-but
>rather let Spring instantiate them by calling Spring's BeanFactory
>methods.

>However, for the BeanFactory instantiation to work, one has to have the
>proper XML configuration file written. THIS is the question I was
>asking:  What is the XML I have to write to force Spring to
>automatically call FtpServer.start()?

>See, I need to know how to make SPRING call server.start()---using XML.
>I 'm not asking how to write a Java method call.


Maybe this will help somebody else and maybe somebody has a better way
so I figured I'd post. I essentially have 2 Spring XML configs in the
/WEB-INF directory of my war file (yes this is for a Spring app
deployed to Tomcat) Note my FtpWrapper class has no main method at all
- it's just a wrapper - that calls init - I'm sure there may be a more
elegant way but sometimes good enough is better. :)

The 1st config file in WEB-INF is spring-config.xml that contains all
my web apps beans configs and lastly:

       [snip]

   <!-- ftpserver/ftplet config -->
   <bean id="serverTest" class="my.ftp.FtpWrapper" destroy-method="destroy">
           <property name="FTPServer" ref="myFtpServer" />
   </bean>


The 2nd config file in /WEB-INF I have is called config-ftplets.xml -
it should look familiar. :)

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://mina.apache.org/ftpserver/spring/v1";
   xmlns:beans="http://www.springframework.org/schema/beans";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://mina.apache.org/ftpserver/spring/v1
http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
   ">

   <server id="myFtpServer">
       <listeners>
           <nio-listener name="default" port="3939">
           </nio-listener>
       </listeners>
              <ftplets>
           <ftplet name="myFtplet">
               <beans:bean class="my.ftp.FtpFtplet">
               </beans:bean>
           </ftplet>
       </ftplets>
       <file-user-manager file="/WEB-INF/ftp.properties" />
   </server>
</beans:beans>

Note: I renamed users.properties to ftp.properties and pointed it to
WEB-INF where it resides.

Oh yeah, since you'll also need to modify your web.xml to point to
both configs like so:

        <!-- Spring App Context -->
        <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                        /WEB-INF/spring-config.xml
                        /WEB-INF/config-ftplets.xml
                </param-value>
        </context-param>

If anybody has any alternate/better ideas on getting the server
started in Spring - in Tomcat - please post! Getting the Spring config
sorted out was not at all easy - our resident Spring guru helped me a
great deal! ;)

Reply via email to