Posted by Prabu on 06:16
CORE Spring
1)What is Spring?
Spring is a open source. It is reverse of JNDI (Java Naming Directory Interface). The trickier part of spring is XML configuration. Now this also made it easily.Through using Annotations. This technique is newly introduce in Spring 3.0 so on.
Features of Spring;
1.
Lightweight - less size and less overhead
2.
Inversion of control -
reverse of JNDI
3.
Aspect-oriented - Separating the Business logic.
4.
Container - manages the lifecycleFramework
2)Why we are using spring?
The beauty of the spring is it reduce the code. The configuration are made in through XML file and annotation (JSR-250). Suppose we need to change the code in program ,it is complex.Here we change xml configuration file only.
3)Simple code in core java
1.spring-config.xml
2.Main.java
3.Bean.java
Main.java
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
pubic class Main1.spring-config.xml
2.Main.java
3.Bean.java
Main.java
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
{
public static void main(String args[])
{
XmlBeanFactory beanfactory = new XmlBeanFactory(new ClassPathResource("springconfig.xml");
Bean beanObj = beanfactory.getBean("Obj");
System.out.println(beanObj.getMessage());
}
}
Bean.java
public class Bean
{
private String message;
public void setMessage(String message)
{
this.message=message;
}
public String getMessage()
{
return message;
}
}
springconfig.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="Obj" class="Bean">
<property name="message" value="Hello Spring World!"/>
</bean>
</beans>
Previous Next
Subscribe to:
Posts (Atom)