Simple Getting Started test for the Java development--spring framework

Source: Internet
Author: User

-MyEclipse to automatically import the jar packages required by the spring framework
-Spring Getting Started test

1. To import the jar package required by spring

Description :
Here spring requires a jar pack to be myeclipse in the box without additional downloads, and if it is another authoring tool please find the installation directory Configuration\org.eclipse.osgi\53\0.cp\data\4.1.0\ Dist files under the jar package, you can also download the add yourself

2. Spring Getting Started test

A. Creating a new class to write a method to test

Package test;

public class Userinfo {public
    void sing () {
        System.out.println) ("I'm a big winner.") ");
    }

}

B. Instantiating objects in a configuration file

<?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:p=" http://www.springframework.org/ schema/p "
    xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www.springframework.org/ Schema/beans/spring-beans-4.1.xsd ">
<!--instantiated objects, equivalent to userinfo userinfo = new UserInfo ();-->
    <bean Name= "UserInfo" "class=" test. Userinfo "></bean>
</beans>

c. Building test classes

Package test;

Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;

public class Text {public
    static void Main (string[] args) {
    //Read the spring configuration file, remove the instance
    applicationcontext CTX = new Classpathxmlapplicationcontext ("Applicationcontext.xml");
    The instance
     Userinfo Userinfo = (Userinfo) ctx.getbean ("Userinfo") is obtained from the configuration file object.
     Invoke Method
     userinfo.sing () with object;
     Print address, optional
     System.out.println (userinfo);

    }

D. Results of the operation

Related Article

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.