Spring two things (1), spring

Source: Internet
Author: User

Spring two things (1), spring

Let's give a brief introduction to spring. On the one hand, let's get started with new users, and on the other hand, let's repeat them.
Maven is not used for the first small factory, and maven is used for configuration next time.

Only one jar package is required. The spring version is 2.5 (2.5 for the time being, and the basic core is the same for subsequent updates). Introduce spring. jar to lib as follows:

Create the applicationContext. xml file under src. The result is as follows:

The content is as follows:

<? 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: context = "http://www.springframework.org/schema/context" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/sprin G-context-2.5.xsd "> <! -- Put a class into the spring container. This class is called bean --> <! -- Describe a class id that uniquely identifies the class name --> <bean id = "helloWorld" class = "com. lee. spring001.createobject. HelloWorld"> </bean> </beans>

Create a new class HelloWorld. java under the com. lee. spring001.createobject package:

package com.lee.spring001.createobject;public class HelloWorld {    public HelloWorld() {        System.out.println("HelloWorld...");    }    /**     *      */    public void hello() {        System.out.println("Hello world!");    }}

Test:

 1 package com.lee.spring001.createobject; 2  3 import org.junit.Test; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.support.ClassPathXmlApplicationContext; 6  7 public class HelloWorldTest { 8  9     @Test10     public void testHelloWorld() {11         12         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");13         15         HelloWorld hello = (HelloWorld)context.getBean("helloWorld");16         hello.hello();17     }18 }

The junit operation is successful.

 

Github address: https://github.com/leechenxiang/maven-spring001-helloworld

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.