The IDE used by this demo is JBuilder X, in fact, I have more admiring Eclipsh, because unprinted, use JBuilder to do one. First you need to download the Spring framework, where I won't say it. Create a project with JBuilder X, build two classes. Need to join two libary.spring-core.jar and commons- logging.jar. To write our first component (Component), it is just a simple JavaBean, which is used to hear a new user:
Hellobean.java
Package package untricled9;
Public class hellobean {
Private string helloword = "Hello! World!";
Public void sethelloword (string helloword) {
THIS.HELLOWORD = HelloWord;
}
Public string getHelloword () {
Return HelloWord;
}
}
Hellobean has a preset "Hello! World!" String, we can also set new converbers through Setter, but we don't personally write programs to make these things, but in confirming file definition, from Spring. For our set action, we write bean.xml:
Bean.xml
xml version = "1.0" encoding = "UTF-8"?> Hellobean Hello = (Hellobean) Factory.getBean ("Hellobean"); System.out.println (Hello.getHelloword ()); } } This is from the relatively low-level angle using Spring IOC container feature, and is to read the configuration file and complete the dependence on the dependencies. What is the dependence on this? It refers to the Hellobean phase, which is used by the String object. Through the interface reserved by Setter, we use setter injection to complete this dependency injection, not to write the words in Hellobean, beanfactory is the focus of the entire Spring, the core of the entire Spring Around it, use XMLBeanFactory here, responsible for reading XML configuration files, of course, we can also use the Properties file, which will be introduced later. BeanFactory reads the configuration of Bean and completes the relationship maintenance, we can get an instance by getBeaN () method and specify the alias of the bean to see the effect after the actual operation: 2005-2-2 13:38: 34 org.springframework.beans.Factory.xml.xmlbeandefinitionReader loadingBeandefinitions Information: Loading XML Bean Definitions from Resource Loaded THROUGH INPUTSTREAM 2005-2-2 13:38:34 Org.springframework.beans.Factory.support.AbstractBeanFactory GetBean Information: Creating Shared Instance of Singleton Bean 'Hellobean' Hello! Justin!