File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring 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.
subject: Injecting a Dependency through Spring
It's not a secret anymore!