This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Injecting a Dependency through Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Injecting a Dependency through Spring " Watch "Injecting a Dependency through Spring " New topic

Injecting a Dependency through Spring

Richa Anand

Joined: Aug 27, 2005
Posts: 6
Hello All,
I�m new to spring and DI pattern. I have taken all the required steps like created a development environment similar to Spring sample applications.
For instance,
D:\spring-framework-1.2\samples\BikeRental\src is the directory where I have kept all the source code files.
war\WEB-INF\RentABikeApp-context.xml Spring Configuration file
war\WEB-INF\lib directory where I have copied the Spring JAR files

My �src� directory has the following files � a simple POJO � interface/service � implementation class � my client class � this is the third party code

What I�m trying to do here is to inject dependencies through Spring third party code.
Below is the code for the Spring assembler

public class RentABikeAssembler {
public static final void main(String[] args) {
ClassPathXmlApplicationContext ctx = new
CommandLineView clv =
clv.printAllBikes( );

And, my Spring configuration files goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<bean id="rentaBike" class="ArrayListRentABike">
<property name="storeName"><value>"Bruce's Bikes"</value></property>
<bean id="commandLineView" class="CommandLineView">
<property name="rentaBike"><ref bean="rentaBike"/></property>

But, when I run the assembler i get the following runtime exception:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore
Exception: IOException parsing XML document from class path resource [RentABikeA
pp-context.xml]; nested exception is class path r
esource [RentABikeApp-context.xml] cannot be opened because it does not exist

Can anybody help.
I agree. Here's the link:
subject: Injecting a Dependency through Spring