Since the most recent task is about converting the format of the IOC configuration file, you need to start learning from the Spring IoC container. Today, based on the introduction on the Internet, we have set up the spring environment, the IOC container has a preliminary experience. The software involved in the article and the recommended Spring IoC container ebook will be appended with my Baidu Network Disk at the end to prevent maintenance on the official website or other floating cloud situations. Appendix ~
1. Open http://www.springsource.org/spring-community-download. as shown in, click take me to the download page.
2. Go to the download page and select the latest version for download.
3. After the download is complete, decompress the package to any folder. The directory structure is clear at a glance.
4. Open eclipse, create a Java project, right-click the project name → build path → configure build path, and select Add external jars in the open window.
5. Then in the jar selection window find the path you just decompressed, enter the libs folder, select spring-beans-3.2.1.RELEASE.jar, spring-context-3.2.1.RELEASE.jar, spring-core-3.2.1.RELEASE.jar, spring-expression-3.2.1.RELEASE.jar, open and click OK to add successfully.
6. Open Logging
7. After the preparation is complete, start the initial experience of IOC and create the following directory structure:
8. The code for each file is as follows:
Beana. Java
1 package org.beans;2 3 public class BeanA {4 public void say(){5 System.out.println("welcome");6 }7 }
Beanb. Java
1 package org.beans; 2 3 public class BeanB { 4 private BeanA ba ; 5 6 public BeanA getBa() { 7 return ba; 8 } 9 10 public void setBa(BeanA ba) {11 this.ba = ba;12 }13 14 }
Start. Java
1 package org.beans; 2 3 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.support.ClassPathXmlApplicationContext; 5 6 public class Start { 7 public static void main(String[] args) { 8 ApplicationContext ctx = new ClassPathXmlApplicationContext("org/beans/applicationContext.xml"); 9 BeanB bb = (BeanB) ctx.getBean("beanB");10 bb.getBa().say();11 }12 }
Applicationcontext. xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:p="http://www.springframework.org/schema/p" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> 8 <bean id = "beanB" class = "org.beans.BeanB"> 9 <property name = "ba" ref = "beanA"/>10 </bean>11 <bean id = "beanA" class = "org.beans.BeanA"/>12 </beans>
After running the program, the console outputs welcome ~~
The jar package involved in this article and the introduction to the Spring IoC container. Download link:
Http://pan.baidu.com/share/link? Consumer id = 408901 & UK = 152821134
If you have any shortcomings, I hope the experts will point out that if you have any questions, you are welcome to discuss them ~~