i am creating a business class but i need the class to have access to application context, how can i inject it to my business class or what class should i extend?
thanks
i am creating a business class but i need the class to have access to application context, how can i inject it to my business class or what class should i extend?
thanks
ok i tried that but why I am having
org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'utilities' is defined:
the bean utilities is defined in another xml, which I imported on the top xml.
my billing-servlet.xml
my applicationContext-jdbc.xmlCode:<beans> <import resource="xml/utility.xml"/> .... <bean id="ratesMeterController" class="billing.mock.RatesMeterController"> <property name="methodNameResolver" ref="ratesMeterControllerResolver"/> <property name="billing" ref="billingImpl"/> </bean> ...
my billingImpl class looks like thisCode:... <bean id="billingImpl" class="com.controller.BillingImpl" lazy-init="true"> <property name="dataSource" ref="dataSource"/> </bean> ....
Code:public class BillingImpl implements Billing,ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext){ this.applicationContext=applicationContext; } public ApplicationContext getApplicationContext(){ return applicationContext; }
if i get that bean from my controller it's ok, but if i get it from my business class that implemented ApplicationContextAware, it says no bean defined.
what gives?
any ideas?
thanks again...
Could you post the surce code that you use to get "that" bean?if i get that bean from my controller it's ok, but if i get it from my business class that implemented ApplicationContextAware, it says no bean defined.
I guess you are using ApplicationContextListener to load applicationContext-jdbc.xml and DispatchServlet to load billing-servlet.xml, right?
Spring, actually, will create two ApplicationContexts, a root ApplicationContext loaded by the listener and a child one loaded by the DisplacthServlet. Beans in the root AC are visible to beans in the child AC. the inverse is not correct. If my original assumption is true, you can access "that" bean from the controller because it is defined in the xml/utility.xml file (included in billing-servlet.xml).
To solve this issue you may remove the <import resource ...> from billing-servlet.xml and put it in applicationContext-jdbc.xml (this depends on what beans are declared in that file)
Hope this helps
ic..
thanks a lot for the help...
more power...