Announcement Announcement Module
Collapse
No announcement yet.
Load applicationContext.xml,use BeanFactory out of web app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load applicationContext.xml,use BeanFactory out of web app

    i want to use spring+hibernate in a swt/swing application, so i search the document about spring,but i found that, all the examples introduce how to
    load applicationContext.xml and use BeanFactory in webapp,such as
    in web.xml
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext-hibernate.xml</param-value>
    		<!--
    		<param-value>/WEB-INF/applicationContext-ojb.xml</param-value>
    		-->
    		<!--
    		<param-value>/WEB-INF/applicationContext-jdbc.xml</param-value>
    		-->
    	</context-param>
    Code:
    	<servlet>
    		<servlet-name>context</servlet-name>
    		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    but my application has not a app server and don't need one.
    so, how can i use spring +hibernate in a swt/swing application
    does i must write code to mannul create a BeanFactory and read applicationContext.xml???

    Are there some examples or project can referrenced?[/code]

  • #2
    I recommend use spring application context without application server instead of BeanFactory.

    Comment


    • #3
      Originally posted by siverhoof
      I recommend use spring application context without application server instead of BeanFactory.
      does i must write some code to create a ApplicationContext?are there some examples?

      Comment


      • #4
        Code:
        package org.taha;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.support.ClassPathXmlApplicationContext;
        
        public class Testos &#123;
          private static final String&#91;&#93; LOCATIONS = &#123;"org/taha/applicationContext.xml"&#125;;
        
          public static void main&#40;String&#91;&#93; args&#41; throws Exception &#123;
            ApplicationContext context = new ClassPathXmlApplicationContext&#40;LOCATIONS&#41;;
            SomeClass bean = &#40;SomeClass&#41; context.getBean&#40;"myBean"&#41;;
        
          &#125;
        &#125;
        HTH

        Comment


        • #5
          Originally posted by irbouho
          Code:
          package org.taha;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
          
          public class Testos &#123;
            private static final String&#91;&#93; LOCATIONS = &#123;"org/taha/applicationContext.xml"&#125;;
          
            public static void main&#40;String&#91;&#93; args&#41; throws Exception &#123;
              ApplicationContext context = new ClassPathXmlApplicationContext&#40;LOCATIONS&#41;;
              SomeClass bean = &#40;SomeClass&#41; context.getBean&#40;"myBean"&#41;;
          
            &#125;
          &#125;
          HTH
          thanks

          Comment

          Working...
          X