java class in spring
i have been asked to write a java class in spring framework.. and i have to idea from where to start please help me
i have been asked to write a java class in spring framework.. and i have to idea from where to start please help me
You don't write them "in" the spring framework. Spring works upside-down to that, generally. You use Spring to configure your Java objects, typically from XML. Best thing is to read a Spring tutorial on it. If you don't know what IoC and dependency injection means, it might be a bit tricky to get your head round at first, but it's really simple to be honest
A good book is "Spring in Action" you can buy on-line if you have time to read it before your project is due. If not, still read it, but for now talk to someone on your team that knows Spring and have him outline what needs to be done. If you take the second route, you probably need to read up on dependency injection, etc like the previous post mentioned.
Here's a very simple Spring IoC example
start with a bean class
package com.sample.spring.bean;
public class MyBean {
private String fullName;
public void setFullName(String fullName) {
fullName = fullName;
}
public String getFullName() {
return fullName;
}
}
then a bean definition file (typically in XML) we'll call it config.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="myBean" class="com.sample.spring.bean.MyBean">
<property name="fullName" value = "John C. Random" />
</bean>
</beans>
then instantiate an ApplicationContext
public class RunMyApp {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("config.xml");
MyBean bean = (MyBean) ctx.getBean("myBean");
System.out.println(bean.getFullName());
}
}
That's about it. Obviously things can be somewhat more complex than that, but this is a start. Read the book below, though, about as good a text on Spring as you're likely to find (by the guy who wrote most of Spring)
http://www.amazon.co.uk/Professional-Java-Development-Spring-Framework/dp/0764574833/ref=pd_bbs_sr_2/203-6236725-0531957?ie=UTF8&s=books&qid=1184938247&sr=8-2
> thanx everybody for ur guidance
Ur guidance:
http://www.mnsu.edu/emuseum/archaeology/sites/middle_east/ur.html
~