This essay developed out of conversations I've had with several other programmers about why Java smelled suspicious. It's not a critique of Java!
Sycorax - complete tutorials
Programming Tutorials
" Java provides the industry - software companies and customer alike , an opportunity to create a true open computing environment where software is portable,
and customers benefit from increase competition. "
Spring Framework Overview
Benefits of Spring Framework
Installing and downloading
Spring Framework
Whats new in spring 2.0?
Introduction to IOC
Setter Injection
Constructor Injection
Spring MVC
Spring and Hibernate
Spring Web Framework
Spring Web Flow
Spring AOP
Register now to recieve special alert and latest technology news!
IOC (Inversion Of Control)/ DI (Dependency Injection) - Constructor Injection
Example Code of Constructor Injection - You need to create three files beans.xml, User.java and the main class Main.java Then run the class Main.java . You need spring.jar file in your classpath .
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="user" class="sycorax.sinjection.User" >
<constructor-arg index="0" type="java.lang.String" value="sycorax"/>
<constructor-arg index="1" type="java.lang.String" value="kolkata"/>
<constructor-arg index="2" type="java.lang.String" value="info@sycorax.co.in"/>
</bean>
</beans>
User.java
package sycorax.sinjection;
/**
*
* @author sycorax.co.in
*/
public class User {
private String name;
private int addr;
private String email;
public User(String name, String addr, String email){
this.name = name;
this.addr = addr;
this.email = email;
}
public String getName() {
return name;
}
public int getAddr() {
return addr;
}
public String getEmail() {
return email;
}
public String toString() {
return "Name :"+name + " Address: " + addr + " Email: " + email;
}
}
Main.java
package springinjection;
/**
*
* @author sycorax.co.in
*/
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main2 {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
User user = (User)context.getBean("user");
System.out.println(user);
}
}
