[Spring] analyzes the establishment of the Spring framework and the spring framework

Source: Internet
Author: User

[Spring] analyzes the establishment of the Spring framework and the spring framework

Directory structure:

Contents structure [-]
  • References
  • What is Spring?

    Spring is a container framework used to configure beans and maintain the relationship between beans.

    Structure Diagram of Spring:

    Simple Spring framework setup Demo

    My structure directory:

    Create a User class

    package com.server;public class User {  private String name;public void getName() {    System.out.println("Hello "+name);}public void setName(String name) {    this.name = name;}}

     

  • Create a Test class
    Package com. test;/** introduce ApplicationContext and ClassPathXmlApplication */import org. springframework. context. applicationContext; import org. springframework. context. support. classPathXmlApplicationContext; import com. server. user; public class Test {public static void main (String [] args) {ApplicationContext ac = new ClassPathXmlApplicationContext ("applicationContext. xml "); User user = (User) ac. getBean ("user"); // identifies the user based on the Bean id. getName ();}}

    Applicationcontextis an interface. classpathxmlapplicationcontextsearches for applicationcontext. you can find an index.html webpage file in the development kit. You can find the API documentation of the corresponding Spring version.

    ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
  • Create an applicationContext File
    <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: context = "http://www.springframework.org/schema/context" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: p = "http://www.springframework.org/schema/p" xmlns: util = "http://www.springframework.org/schema/util" xmlns: jdbc = "h Ttp: // www.springframework.org/schema/jdbc "xmlns: cache =" http://www.springframework.org/schema/cache "xsi: schemaLocation =" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springfram Ework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http: // ww Export springframework.org/schema/util/spring-util.xsd "> <! -- Configure bean (service/dao. domain/action/Data Source) in the container file; --> <! -- Bean is used to automatically create a bean object and put it into the memory when our Spring framework is loaded. Id is the identifier, and the class specifies the path. In this example, it is equivalent to: User user = new User (); user. setName ("" chauncy); --> <bean id = "user" class = "com. server. user "> <property name =" name "> <value> chauncy </value> </property> </bean>
    </Beans>

     

  • References

    Http://blog.csdn.net/zoutongyuan/article/details/27073683

     

    This article is an original blog article. If you need to reprint it, please indicate the source.

    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.