Results 1 to 5 of 5

Thread: Spring with Desktop Application.

  1. #1
    Join Date
    Mar 2007
    Posts
    10

    Default Spring with Desktop Application.

    Hi,

    I just started learning about spring and used it's MVC ... about which i am very impressed. It really eased a lot of problems for us. However, I am a bit confuse about using it with some desktop application.

    The basic confusion lies in Controllers classes. What ever spring i have used, i used action-servlet.xml to specify the web pages, to add bean injection and the FormController and SimpleController to make pages. But i am unable to get any idea how to use it with Desktop Application.

    It'd be great if some of you refer to me any sample Desktop Spring based application, what was the scenario for it and how it is architeched with spring.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    It depends what you mean here. Are you looking to write a standalone desktop application, or are you looking to write a client/server style application?

  3. #3
    Join Date
    Mar 2007
    Posts
    10

    Default

    Quote Originally Posted by karldmoore View Post
    It depends what you mean here. Are you looking to write a standalone desktop application, or are you looking to write a client/server style application?
    for the time being i am looking for client/server desktop based application using either swing or swt.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    The reference manual has a chapter on remoting, this might be useful. I used HttpInvoker on a previous Swing project that worked very nicely.
    http://www.springframework.org/docs/.../remoting.html

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Here's an example I posted on another thread a while back. The project in this example is called timeService.

    Sooooo
    Code:
    tomcat
        webapps
            timeService
                applicationContext.xml
                invoker-servlet.xml
                web.xml
    
                classes
                    com/test/TimeService.class
                    com/test/TimeServiceImpl.class
                lib
                    spring.jar
                    commons-logging-1.0.4.jar
    The client will also require commons-codec.jar and commons-httpclient.jar on the classpath as well as the server prereqs.

    Client

    TimeServiceClient
    Code:
    package com.test;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class TimeServiceClient
    {
    	public static void main ( String [] args )
    	{
    		ApplicationContext context = new ClassPathXmlApplicationContext ( "client-applicationContext.xml" );
    		TimeService timeService = ( TimeService ) context.getBean ( "timeService" );
    		System.out.println ( timeService.getDate () );
    		sleepPlease ();
    		System.out.println ( timeService.getDate () );
    	}
    	
    	private static void sleepPlease ()
    	{
    		try
    		{
    			Thread.sleep ( 5000 );
    		}
    		catch ( InterruptedException e )
    		{
    			// ignore
    		}
    	}
    }
    client-applicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="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.0.xsd">
         
        <bean id="httpInvokerRequestExecutor" class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"/>
    
        <bean id="timeService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    		<property name="serviceUrl" value="http://localhost:8080/timeService/invoker/timeService"/>
    		<property name="serviceInterface" value="com.test.TimeService"/>
            <property name="httpInvokerRequestExecutor">
                <ref bean="httpInvokerRequestExecutor"/>
            </property>
        </bean>
        
    </beans>
    Server

    TimeService
    Code:
    package com.test;
    
    import java.util.Date;
    
    public interface TimeService
    {
    	Date getDate ();
    }
    TimeServiceImpl
    Code:
    package com.test;
    
    import java.util.Date;
    
    public class TimeServiceImpl implements TimeService
    {
    	public Date getDate ()
    	{
    		return new Date ();
    	}
    }
    applicationContext.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="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.0.xsd">
           
           <bean id="timeService" class="com.test.TimeServiceImpl"/>
           
    </beans>
    invoker-servlet.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="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.0.xsd">
           
    	<bean name="/timeService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
            <property name="service">
                <ref bean="timeService"/>
            </property>
            <property name="serviceInterface">
                <value>com.test.TimeService</value>
            </property>
        </bean>
        
    </beans>
    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC
    	"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    	"http://java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
    	<display-name>Time Service</display-name>
    	<description>Time Service</description>
    
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    
    	<servlet>
    		<servlet-name>invoker</servlet-name>
    		<servlet-class>
    			org.springframework.web.servlet.DispatcherServlet
    		</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>invoker</servlet-name>
    		<url-pattern>/invoker/*</url-pattern>
    	</servlet-mapping>
    
    </web-app>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •