It's not dependency injection if you are looking up and grabbing a service in a 
factory.  Nothing is being injected.  The beauty of DI is too vast to describe 
in email, but it is a more declarative model.  You declare a service with an 
interface in the DI container.  You then declare that you want to use that 
service in your "thing" by adding it as a member variable.  Assuming your thing 
has told the DI container that it would like its services injected, the 
container will see the variable with the matching interface and "inject" a 
fully instantiated service based on what you declared earlier.  (As part of the 
declaring a service you register the interface AND tell it what implementation 
to use).

There are lots of options like wiring by name rather than type, annotations vs. 
xml configuration, etc.  I suggest you pick up Spring In Action (Manning), read 
the Spring Framework documentation and complete the Appfuse tutorials.    That 
should help with your first two questions.

As for question #3:  Each datasource is declared as a service with Spring.  You 
would then wire the correct datasource to the correct DAO using the DI 
container xml or annotations.

Finally, in the same file you configure datasources 
(applicationContext-resources.xml) there is a small block there for what are 
called PropertyPlaceholders.  If you add a reference to your config file there 
(and put it where you say it is) you can use a nifty Spring 3.0 feature.  Where 
you want that value in your object you can annotate a member variable with 
@Value(${"property.name"}). 

-D  

On Mar 23, 2010, at 11:44 PM, mlounnaci wrote:

> Hello,
> 
> Thanks for answer
> 
> I made that because I want to use a sort of dependency injection in my 
> application. Is there a simpler way to do it?
> 
>  
> 
> Other questions:
> 
>  
> 
> 1-      How to call a DAO function from another class inside my appfuse 
> application? I tried to instantiated the DAOHibernate class but it didn’t 
> work (NullPointerException when calling a function)
> 
> 2-      I my application I have two access two databases : MySql & SQL 
> Server, how to load hibernate configuration for the second database?
> 
> 3-      I want to use a configuration file to store some private params. What 
> is the best way?
> 
>  
> 
> I am sorry for the length of my question.
> 
> Regards
> 
>  
> 
>  
> 
> From: mraible [via AppFuse] [mailto:[hidden email]] 
> Sent: Tuesday, March 23, 2010 3:41 PM
> To: mlounnaci
> Subject: Re: applicationContext.xml not found
> 
>  
> 
> Why do you want to do this? Why not simply inject the service you're looking 
> for into your WebService class? 
> 
> On Mar 23, 2010, at 3:20 AM, mlounnaci wrote:
> 
> 
> > 
> > 
> > Hello friends 
> > 
> > I tried to use the following  inside my webservice method : 
> > 
> > BeanFactory factory = new XmlBeanFactory(new 
> > ClassPathResource("/WEB-INF/applicationContext.xml")); 
> > 
> > The exception resulted: 
> > 
> > .....org.springframework.beans.factory.BeanDefinitionStoreException: 
> > IOException pars 
> > ing XML document from class path resource 
> > [/WEB-INF/applicationContext.xml]; 
> > nested excep 
> > tion is java.io.FileNotFoundException: class path resource 
> > [/WEB-INF/applicationContext.xml] cannot be opened because it does not 
> > exist 
> > 
> > How can i locate my applicationContext.xml file? 
> > 
> > Thanks for help. 
> > -- 
> > View this message in context: 
> > http://n4.nabble.com/applicationContext-xml-not-found-tp1678836p1678836.html
> > Sent from the AppFuse - User mailing list archive at Nabble.com. 
> > 
> > --------------------------------------------------------------------- 
> > To unsubscribe, e-mail: [hidden email] 
> > For additional commands, e-mail: [hidden email] 
> >
> 
> 
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: [hidden email] 
> For additional commands, e-mail: [hidden email] 
> 
> 
> 
> View message @ 
> http://n4.nabble.com/applicationContext-xml-not-found-tp1678836p1679257.html 
> To start a new topic under AppFuse - User, email [hidden email] 
> To unsubscribe from AppFuse - User, click here.
> 
>  
> 
> 
> View this message in context: RE: applicationContext.xml not found
> Sent from the AppFuse - User mailing list archive at Nabble.com.

Reply via email to