New lightweight Java Open source Framework---Spring
Egg
Weibo : Http://weibo.com/xtfggef
Source:http://blog.csdn.net/zhangerqing
Spring is a lightweight Java framework whose core idea is Di (Dependency injection, which is dependency injection) and IOC (inversion of control, that is, controlled inversion) because of its open source, low intrusion, It has now swept through a large segment of the market, its biggest competitor being the Java EE Framework EJB. EJB3.0 ago, because of its cumbersome and cumbersome use, people are helpless to abandon, instead of spring, but spring has its limitations, that is, the spring on the distributed support is not good, but the EJB in this area is very advantageous, and the current EJB3.0 simplifies the operation, the use is no longer cumbersome, the competitiveness further improve 。 Therefore, the current lightweight Javaweb project, a lot of the use of spring, we need to learn it well! This chapter is the beauty of Java [from rookie to master evolution] series of Spring Framework, I hope you and I together, again review the basic knowledge of spring, and actively put forward valuable comments and suggestions! This study uses the Spring4.1 version.
Modules
From this picture we can see that the overall architecture of spring, mainly divided into six modules
Core container is divided into 4 chunks, spring-core, Spring-beans, Spring-context, Spring-expression. Core and Bean are the cores of the entire framework, providing the basis for Di and IOC functionality. The context is built on the core and beans modules, providing a way to manipulate objects in a way that is similar to Jndi and is framed. The context module inherits its functionality from the Beans module while increasing internationalization support, such as resource binding, while the context module supports Java EE functions such as EJB,JMX and basic remote invocation. The ApplicationContext interface is the focus of the context module. Expression is a powerful expression language that supports querying and manipulating the properties of objects at run time, and we'll cited some examples of the use of Spring expression language in a later article. AOP and Instrumentation
The AOP module provides the implementation of aspect-oriented programming, and ASPECTJ integration.
Messaging
Messaging is a new addition to the Spring4 module, which contains some of the main implementations of message-based applications.
Data access/integration
Data access, as its name implies, is spring's support for the data layer, which is a more versatile module. Provides a range of implementations including JDBC, things, ORM,JMS, and more.
Web
Web modules primarily provide web-oriented implementations such as multi-file uploads, servlet listeners, and spring MVC support.
Test
The test module is designed to perform a variety of tests for each of the spring's modules, including unit testing, integration testing, and so on.
Specific explanations and functions of each module we will mention in the following article, and also ask interested readers to check the official spring documentation for more detailed instructions.
The first spring applet
Create a new user class, a Userdao class, and a test class:
User.java
[Java]View PlainCopy
- Package Com.adam.java.spring.po;
- Public class User {
- private String name;
- private int age;
- private int score;
- Public String GetName () {
- return name;
- }
- public void SetName (String name) {
- this.name = name;
- }
- public int getage () {
- return age;
- }
- public void Setage (int.) {
- this.age = age;
- }
- public int Getscore () {
- return score;
- }
- public void SetScore (int score) {
- This.score = score;
- }
- Public String toString () {
- return "tostring from user";
- }
- }
Userdao.java
[Java]View PlainCopy
- Package Com.adam.java.spring.dao;
- Import Com.adam.java.spring.po.User;
- Public class Userdao {
- Private User User;
- public Void Add () {
- System.out.println ("Add from Userdao");
- System.out.println (User.tostring ());
- }
- Public User GetUser () {
- return user;
- }
- public void SetUser (user user) {
- this.user = user;
- }
- }
Ditest.java
[HTML]View PlainCopy
- Package com.adam.java.spring;
- Import Org.springframework.context.ApplicationContext;
- Import Org.springframework.context.support.ClassPathXmlApplicationContext;
- Import Com.adam.java.spring.dao.UserDao;
- public class Ditest {
- @SuppressWarnings ("resource")
- public static void Main (string[] args) {
- ApplicationContext ATX = new Classpathxmlapplicationcontext ("Beans.xml");
- Userdao Userdao = (Userdao) atx.getbean ("Userdao");
- Userdao.add ();
- }
- }
A configuration file Beans.xml
[HTML]View PlainCopy
- <? 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="user" class="Com.adam.java.spring.po.User"/>
- <Bean id= "Userdao" class="Com.adam.java.spring.dao.UserDao">
- <property name="user" ref="user"/>
- </Bean>
- </Beans>
Execute the test class to produce the following output:
[HTML]View PlainCopy
- Add from Userdao
- ToString from user
- from:http://blog.csdn.net/zhangerqing/article/details/8546049
New lightweight Java Open source Framework---Spring