Spring is an open source framework. Spring is a lightweight Java development framework that emerged in 2003 and was created by Rod Johnson. In short, Spring is a layered JavaSE/EEfull-stack (one-stop) lightweight open source framework.
Spring Author: Rod Johnson;
Official website: http://spring.io/The
latest development kit and document download address: http://repo.springsource.org/libs-release-local/org/springframework/spring/Core
idea:
1 , IOC Inversion of Control;
2. AOP is aspect-oriented;
Section 2: Spring4 version of HelloWorld implementation
Attached source code
HelloWorld.java
package com.java.fx.test; public class HelloWorld { public void say(){ System.out.println("Spring4获取bean!"); } }
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="helloWorld" class="com.java.fx.test.HelloWorld"></bean> </beans>
Test.java
package com.java.fx.service; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.java.fx.test.HelloWorld; public class Test { public static void main(String[] args) { ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml"); HelloWorld helloWorld=(HelloWorld)ac.getBean("helloWorld"); helloWorld.say(); } }