• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Cannot get the reference of Spring bean

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to get the reference of spring bean by passing its name which is defined in the spring configuration file. Instead of getting the referece, I am ended up with null. I couldn't find out the actual cause of it.My spring applications are logically diveded into parts based on the product.

I have two stand alone pplications( but inter dependent), i.e Global Admin and Policy Star.

All the services related to Global app are defined in global-svc-spring.xml and global-cfg-spring.xml
All the services related to Policy star app are defined in ps-svc-spring.xml and ps-cfg-spring.xml

These two applications have their own independent databases.

Fro example When I try to invoke gbl-svc-sysadmin service defined in the global-svc-spring.xml, I ended with Null instead of the reference. which is defiend as follows.


Which is internally depend on gbl-sv (because it is parent of the above service)service which is defiend as follows.


Which is in turn depend on the beans gbl-cfg-db and gbl-rules which are defined in the global-cfg-spring.xml as follows.


But If I invoke any service defiened in the ps-svc-spring.xml, it is successfully gettting invoked. which also has the same structure. Only the global services cannot be invoked. They are ended up with null.

The server, I am using is JBoss 4.2.2 GA.

Any help is highly appriciated.



 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just some basic ideas but -
  • Are you sure that your XML files are being loaded for your global app? Check your web.xml and make sure the dispatcher servlet or context loader listener are configured with the right files in the contextConfigLocation option.
  • Check the server logs - make sure something isn't failing and preventing the classes from loading.
  •  
    Pawan Komaram
    Ranch Hand
    Posts: 91
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Firstly thanks for your response.

    Yeah....Context loader is configured properly with global xmls as well in the web.xml file, I even debugged into the code and have seen that global services are getting loaded into the BeanFactory before policy services, but have not been seen while invoking it, only policy sevices are seen in the BeanFactory while invoking.

    But finally, I have got the solution for it. Actually by default JBoss uses Tomcat's class loader to load the classes of different wars(policy.war global.war) which is not a singleton, a new class loader instance will be used for each war, so classes loaded by first class loader instance cannot be seen by other class loader instances. That is the reason I cannot get the references of global services while launching the policy star application.
    Instead of tomcat's class loader I should use the JBoss loader which is an universal loader and singleton, so that all the classes will be loaded by single class loader can be seen any module.
    This can be configured in the jboss-service.xml of following location.

    D:\jboss-4.2.2.GA\server\default\deploy\jboss-web.deployer\META-INF

    The value should be true for this tag, by default it is false.

    <!-- A flag indicating if the JBoss Loader should be used. This loader
    uses a unified class loader as the class loader rather than the tomcat
    specific class loader.
    The default is false to ensure that wars have isolated class loading
    for duplicate jars and jsp files.
    -->

    <attribute name="UseJBossWebLoader">true</attribute>


     
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    All the Spring beans references will be stored in ApplicationContext. so you should get access to ApplicationContext.getBean( is sample "managername");

    here is link to sample project
    http://www.ziddu.com/download/11120780/springhibernate.zip.html
     
    reply
      Bookmark Topic Watch Topic
    • New Topic