New lightweight Java Open source Framework---Spring

Source: Internet
Author: User

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
  1. Package Com.adam.java.spring.po;
  2. Public class User {
  3. private String name;
  4. private int age;
  5. private int score;
  6. Public String GetName () {
  7. return name;
  8. }
  9. public void SetName (String name) {
  10. this.name = name;
  11. }
  12. public int getage () {
  13. return age;
  14. }
  15. public void Setage (int.) {
  16. this.age = age;
  17. }
  18. public int Getscore () {
  19. return score;
  20. }
  21. public void SetScore (int score) {
  22. This.score = score;
  23. }
  24. Public String toString () {
  25. return "tostring from user";
  26. }
  27. }

Userdao.java

[Java]View PlainCopy 
  1. Package Com.adam.java.spring.dao;
  2. Import Com.adam.java.spring.po.User;
  3. Public class Userdao {
  4. Private User User;
  5. public Void Add () {
  6. System.out.println ("Add from Userdao");
  7. System.out.println (User.tostring ());
  8. }
  9. Public User GetUser () {
  10. return user;
  11. }
  12. public void SetUser (user user) {
  13. this.user = user;
  14. }
  15. }

Ditest.java

[HTML]View PlainCopy 
  1. Package com.adam.java.spring;
  2. Import Org.springframework.context.ApplicationContext;
  3. Import Org.springframework.context.support.ClassPathXmlApplicationContext;
  4. Import Com.adam.java.spring.dao.UserDao;
  5. public class Ditest {
  6. @SuppressWarnings ("resource")
  7. public static void Main (string[] args) {
  8. ApplicationContext ATX = new Classpathxmlapplicationcontext ("Beans.xml");
  9. Userdao Userdao = (Userdao) atx.getbean ("Userdao");
  10. Userdao.add ();
  11. }
  12. }

A configuration file Beans.xml

[HTML]View PlainCopy  
  1. <? XML version= "1.0" encoding="UTF-8"?>
  2. <beans xmlns="Http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/ Beans/spring-beans.xsd ">
  5. <Bean id="user" class="Com.adam.java.spring.po.User"/>
  6. <Bean id= "Userdao" class="Com.adam.java.spring.dao.UserDao">
  7. <property name="user" ref="user"/>
  8. </Bean>
  9. </Beans>


Execute the test class to produce the following output:

[HTML]View PlainCopy  
      1. Add from Userdao
      2. ToString from user
        1. from:http://blog.csdn.net/zhangerqing/article/details/8546049

New lightweight Java Open source Framework---Spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.