1. Preface
Starting from today to write a few articles about spring, to summarize, the recent learning situation, but also want to share with you learn spring experience. I hope you can correct me a lot.
2.Spring Brief Introduction
is the entire architecture diagram of spring, as we can see, spring mainly includes AOP, data access, Web Access and a few chunks of content.
Spring is a Java-based, lightweight EE application framework. So what can spring do? At present, we see a lot of frameworks on the market, such as struts2+spring, Spring+servlet, Spring+ibatis, so it can be said that Spring is a super "bonding platform", can put a lot of technology together to form a whole, Enable each component to perform its maximum efficacy.
3.jar Package Finishing
The jar packages required for spring are organized as follows
Development of the jar package used (core jar package)
? Spring-beans-3.2.0.release.jar
? Spring-context-3.2.0.release.jar
? Spring-core-3.2.0.release.jar
? Spring-expression-3.2.0.release.jar
Log-related jar packages (obtained from dependent resources)
? Commons-logging-1.1.1.jar
? Commons-logging log consolidation, similar to SLF4J, provided by Apache
? Log4j-1.2.15.jar
4. How to get context
1. Use the Classpathxmlapplicationcontext object to get
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >//gets spring's factory that requires the Applicationcontext.xml file to be placed under SRC applicationcontext ctx=new Classpathxmlapplicationcontext ("Applicationcontext.xml"); UserService User=ctx.getbean ("UserService", Userservice.class); User.printtest ();</span>
2.
Use the Filesystemxmlapplicationcontext object to get
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" The >/* file system gets the context and needs to place the Applicationcontext.xml file under the project path */applicationcontext ctx2=new Filesystemxmlapplicationcontext ("Applicationcontext.xml"); UserService User2=ctx2.getbean ("UserService", Userservice.class); System.out.println (User2.getid ()); System.out.println (User2.getname ()); User2.printtest ();</span>
3. Access using the Beanfactory factory
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;" >//creates the bean through beanfactory, has the function of lazy loading, when used, then goes to create resource resource = new Classpathresource ("Applicationcontext.xml") ; Beanfactory beanfactory = new Xmlbeanfactory (Resource); UserService User3 = Beanfactory.getbean ("UserService", Userservice.class); System.out.println (User3.getid ()); System.out.println (User3.getname ()); User3.printtest ();</span>
4. Comparison of the three
Use Classpathxmlapplicationcontext object to get, The applicationcontext.xml must be placed in the load path of the class, which is src
using the Filesystemxmlapplicationcontext object, you must place the Applicationcontext.xml under the project directory, which is below the project path
beanfactory and app Licationcontext the difference
Load mode
? Beanfactory: Lazy loading, initializing with beans
? ApplicationContext: Initializing a Bean object when loading a configuration file
Function
? ApplicationContext offers more features
L International Processing
L Event Delivery
L Bean Automatic Assembly
• Context implementation for a variety of different application tiers
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Spring Learning Note One (Spring brief introduction)