-MyEclipse to automatically import the jar packages required by the spring framework
-Spring Getting Started test
1. To import the jar package required by spring
Description :
Here spring requires a jar pack to be myeclipse in the box without additional downloads, and if it is another authoring tool please find the installation directory Configuration\org.eclipse.osgi\53\0.cp\data\4.1.0\ Dist files under the jar package, you can also download the add yourself
2. Spring Getting Started test
A. Creating a new class to write a method to test
Package test;
public class Userinfo {public
void sing () {
System.out.println) ("I'm a big winner.") ");
}
}
B. Instantiating objects in a configuration file
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns=
"http://www.springframework.org/schema/" Beans "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xmlns:p=" http://www.springframework.org/ schema/p "
xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www.springframework.org/ Schema/beans/spring-beans-4.1.xsd ">
<!--instantiated objects, equivalent to userinfo userinfo = new UserInfo ();-->
<bean Name= "UserInfo" "class=" test. Userinfo "></bean>
</beans>
c. Building test classes
Package test;
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;
public class Text {public
static void Main (string[] args) {
//Read the spring configuration file, remove the instance
applicationcontext CTX = new Classpathxmlapplicationcontext ("Applicationcontext.xml");
The instance
Userinfo Userinfo = (Userinfo) ctx.getbean ("Userinfo") is obtained from the configuration file object.
Invoke Method
userinfo.sing () with object;
Print address, optional
System.out.println (userinfo);
}
D. Results of the operation