aspose file tools
The moose likes Spring and the fly likes Cannot get the reference of Spring bean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Cannot get the reference of Spring bean" Watch "Cannot get the reference of Spring bean" New topic
Author

Cannot get the reference of Spring bean

Pawan Komaram
Ranch Hand

Joined: Dec 08, 2009
Posts: 91
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.



Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4120

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.


  • -Nate
    Write once, run anywhere, because there's nowhere to hide! - /. A.C.
    Pawan Komaram
    Ranch Hand

    Joined: Dec 08, 2009
    Posts: 91
    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>


    Sandeep Software Enginner
    Greenhorn

    Joined: Apr 12, 2010
    Posts: 2
    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


    S.Sandeep Raju,
    Associate Software Enginner.
     
     
    subject: Cannot get the reference of Spring bean
     
    Threads others viewed
    JMS implementation using JNDI in spring application
    Spring JMS Junit problem
    Datasource exception during Spring initialization
    Spring Configuration file using Data Source of type Jndi needed for Server
    Two TransactionTemplate use my single application.
    IntelliJ Java IDE