• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Injecting a Dependency through Spring

Richa Anand
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
1.Bike.java � a simple POJO
2.RentABike.java � interface/service
3.ArryListRentABike.java � implementation class
4.CommandLineView.java � my client class
5.RentABikeAssembler.java � 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

import org.springframework.context.support.ClassPathXmlApplicationContext;
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"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/
<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 java.io.FileNotFoundException: class path r
esource [RentABikeApp-context.xml] cannot be opened because it does not exist

Can anybody help.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic