aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Injecting a Dependency through Spring " Watch "Injecting a Dependency through Spring " New topic
Author

Injecting a Dependency through Spring

Richa Anand
Greenhorn

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.
Similarly,
war\classes
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
ClassPathXmlApplicationContext("RentABikeApp-context.xml");
CommandLineView clv =
(CommandLineView)ctx.getBean("commandLineView");
clv.printAllBikes( );
}

And, my Spring configuration files goes like this:
D:\spring-framework-1.2\samples\BikeRental\war\WEB-INF\RentABikeApp-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/
dtd/spring-beans.dtd">
<beans>
<bean id="rentaBike" class="ArrayListRentABike">
<property name="storeName"><value>"Bruce's Bikes"</value></property>
</bean>
<bean id="commandLineView" class="CommandLineView">
<property name="rentaBike"><ref bean="rentaBike"/></property>
</bean>
</beans>


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.
Regards,
Richa
SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Injecting a Dependency through Spring