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.
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
posted
0
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.
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.
-->
All the Spring beans references will be stored in ApplicationContext. so you should get access to ApplicationContext.getBean( is sample "managername");