Results 1 to 5 of 5

Thread: Is a servlet container a prerequisite for running a spring ?

  1. #1
    Join Date
    Oct 2004
    Location
    Denmark
    Posts
    4

    Default Is a servlet container a prerequisite for running a spring ?

    Is it possible to expose remote services without using a servlet/JSP container (for example by using the RMI registry) with spring ?

    And, is it possible to create a standalone application without a servlet/JSP container ?

    I

  2. #2
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    Yes to both questions.

    For example, something like:
    Code:
    public class ServerImpl extends UnicastRemoteObject  implements ServerIface {
    
    
        public ServerImpl() throws RemoteException {
        }
    
        public static void main(String[] args) {
            new ClassPathXmlApplicationContext("ServerContext.xml");
        }
        
        // Remote interface implementation follows here:
    }

    with a Spring context (ServerContext.xml) looking like:
    Code:
    <beans>
        <bean id="pafService" class="foo.bar.ServerImpl" />
    
        <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
            <property name="serviceName"><value>pafService</value></property>
            <property name="service"><ref bean="pafService"/></property>
            <property name="serviceInterface"><value>foo.bar.ServerIface</value></property>
            <property name="registryPort"><value>yourRegistryPortNo</value></property>
            <property name="servicePort"><value>yourServicePortNo</value></property>
        </bean>
    </beans>
    I've tried to cut out extraneous detaiil, but I hope I've got the essentiials there. When you run the main method, your service will be available on the ports you've specified. You don't need to be running a separate registry.
    For an ordinary stand alone app, your spring context will be different - you won't have the RmiServiceExporter - and after loading the context, you'll probably want to do a bit more in your main method.
    Hope this helps
    Chris Harris
    Carlisle, UK

  3. #3
    Join Date
    Oct 2004
    Location
    Denmark
    Posts
    4

    Default

    It does certainly seems to be a remarkebly easy and flexible -
    thanks a lot.

  4. #4
    Join Date
    Nov 2004
    Posts
    1

    Default

    I can't understand why this code registers my bean :
    Code:
    new ClassPathXmlApplicationContext&#40;"beans.xml"&#41;;
    but this one doesn't :
    Code:
    ClassPathResource res = new ClassPathResource&#40;"beans.xml"&#41;;
    XmlBeanFactory factory = new XmlBeanFactory&#40;res&#41;;
    The fact is I tried the second one first when I read Spring's reference (3.2.1. The BeanFactory).

    Here is my beans.xml file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
    	"http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean id="HelloServer" class="aot.essai.spring.server.HelloServer"/>
    
    	<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
    		<property name="serviceName"><value>HelloService</value></property>
    		<property name="service"><ref bean="HelloServer"/></property>
    		<property name="serviceInterface"><value>aot.essai.spring.Hello</value></property>
    		<!-- defaults to 1099 -->
    		<property name="registryPort"><value>1199</value></property>
    	</bean>
    </beans>
    Any idea ?

  5. #5

    Default

    The reason is that BeanFactories don't eagerly instanciate singletons, while ApplicationContextes do. When using a BeanFactory, you have to call preInstantiateSingletons() explicitely.

    Guillaume

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 4
    Last Post: Oct 22nd, 2005, 07:53 AM
  3. A Spring Class Loader?
    By azzoti in forum Architecture
    Replies: 8
    Last Post: May 7th, 2005, 04:02 AM
  4. Replies: 8
    Last Post: Feb 24th, 2005, 04:26 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

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