SPRINGMVC--hello World

Source: Internet
Author: User

Directly on the code:
1. Write a class that outputs Hello World

Package cn.itcat.spring.sh.ioc.creatobject;

public class HelloWorld {public

    void SayHello () {        
        System.out.println ("Hello Xiajun");     
    }

}

2. Put the class into the spring container

<?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-2.5.xsd ">

     <bean id= "HelloWorld" class= "Cn.itcat.spring.sh.ioc.creatobject.HelloWorld" ></bean>
</ Beans>

3. Testing

package cn.itcast.spring.sh.test;
Import Org.junit.Test;
Import Org.springframework.context.ApplicationContext;

Import Org.springframework.context.support.ClassPathXmlApplicationContext;

Import Cn.itcat.spring.sh.ioc.creatobject.HelloWorld;
         public class Creatobjecttest {@Test public void Testcreatobjest () {/** * 1. Start the spring container * 2. Remove objects from the Spring container * 3. Method of Object Invocation */applicationcontext context = new Classpathxmlapplicationconte
        XT ("Applicationcontext.xml");
        HelloWorld HelloWorld = (HelloWorld) context.getbean ("HelloWorld");
    Helloworld.sayhello (); }

}

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.