Hello World (Spring)

Source: Internet
Author: User
Tags getmessage

Today is really a miserable life, early in the morning did not catch the bus, and then come to the big aunt, all day in the state will be dead, the pain of vomiting for an afternoon, completely unable to work, has been looking at the time, fast to six, and then six points as if the class, get 6:30, why women have dysmenorrhea????? Crazy *100000

In the morning to see the "Spring Combat", saw the assembly bean, after watching the automatic assembly, the feeling still do not understand; This book has been opened countless times do not understand not to see, after a while to open or the same, repeated cycles of countless times!!! Still find the W3school on the previous look at the Spring tutorial, first follow this look, to understand a little, from the beginning of the place to speak; one months ago to see a little, but at that time anxious to do the project, want to become a Daniel, casually looked at, or not, no principle of support, It's not too far to learn words without a heart.

First, a spring Hello world, this is generally the first program of all learning, this is the link to learn https://www.w3cschool.cn/wkspring/dgte1ica.html; this Hello World project indefinitely feeling, see is understand, but total feeling still not master of that feeling. Blogging is to encourage yourself to learn a little bit every day, to record the state of learning, emotions.

hellospring class: defines a message variable, the getter and setter method of the message variable, which is an entity class

 Package Com.lee.happy;  Public class hellospring {        private  String message;      Public void GetMessage () {        System.out.println ("Your message:" + message);    }      Public void setmessage (String message) {        this. Message = message;    }    } 

Mainapp class: inside is the main method, which first creates the application context, loads the configuration file, and then gets the bean named Hello

 PackageCom.lee.happy;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classMainapp { Public Static voidMain (string[] args) {//API Classpathxmlapplicationcontext () creates the context of the application, which loads the beans configuration file and ultimately is based on the provided API, which processes the creation and initialization of all objects. and the beans mentioned in the configuration fileApplicationContext context =NewClasspathxmlapplicationcontext ("Beans.xml"); //Use the Getbean () method of the created context to get the bean you want. This method uses the Bean's ID to return a generic object that can eventually be converted to the actual object, and once the object is available, it can be used to invoke any class method .hellospring obj = (hellospring) context.getbean ("Hello");    Obj.getmessage (); }}

Beans.xml:

<?xml version= "1.0" encoding= "UTF-8"?><!--bonded Bean binder--><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-3.0.xsd ">        class=" Com.lee.happy.HelloSpring ">        <property name=" message " Value= "Hello World" ></property>            </bean></beans>

The results obtained:

Code Cloud:https://gitee.com/lemon_le/w3-Spring

Hello World (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.