Spring Introduction 1: Spring introduction and introduction

Source: Internet
Author: User

Spring Introduction 1: Spring introduction and introduction
1. What is Spring? II. Specific description of Spring 3. Setting up the Spring Environment

      

3. Spring configuration file: one or more Bean configuration files need to be created for a typical Spring project. These configuration files are used to configure beans in the Spring IOC container. Bean configuration files can be stored in classpath or other directories.

4. Create a Spring Project and write HelloWorld:

package com.atguigu.spring.beans;public class HelloWorld {    private String name;        public void setName(String name) {        System.out.println("setName...");        this.name = name;    }        public void hello(){        System.out.println("Hello " + name);    }            public HelloWorld() {        System.out.println("HelloWorld's construct...");    }        }
<?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:util="http://www.springframework.org/schema/util"    xmlns:p="http://www.springframework.org/schema/p"    xsi:schemaLocation="http://www.springframework.org/schema/beans   
              http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <bean id="helloworld" class="com.atguigu.spring.beans.HelloWorld"> <property name="name" value="spring"></property> </bean></beans>
Package com. atguigu. spring. beans; import org. springframework. context. ApplicationContext; import org. springframework. context. support. ClassPathXmlApplicationContext;
Public class Main {public static void main (String [] args) {/* HelloWorld helloWorld = new HelloWorld (); helloWorld. setName ("spring"); helloWorld. hello (); * // 1. create container ApplicationContext ctx = new ClassPathXmlApplicationContext ("appliactionContext. xml ");
// 2. Obtain bean HelloWorld hello = (HelloWorld) ctx. getBean ("helloworld") from the container ");
// 3. Call the bean method hello. hello ();}}

5. Test Results

 

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.