Spring environment configuration under eclipse

Source: Internet
Author: User

1) Tools: (1) JDK

(2) Spring.jar, Commons-logging-1.1.1.jar (because it's just a simple demo, so just use these two jar packages)

Spring.jar is a single jar package that contains a complete release module. But not including Mock.jar, Aspects.jar, Spring-portlet.jar, and Spring-hibernate2.jar.

The Commons-logging.jar package is a prerequisite package that uses spring. Log records that are used to record the activity of the program when it is run.

After importing the jar in the IDE, you can start writing tests

2) write the configuration file under SRC

The relevant documents are as follows: Spring-demo.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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.0.xsd ">          <BeanID= "Testbean"class= "Com.gdut.springdemo.Spring">        < Propertyname= "Myspring">            <value>This is my first spring!</value>        </ Property>    </Bean></Beans>

Test class: Spring.java

 PackageCom.gdut.springdemo; Public classSpring {PrivateString myspring;  Public voidShow () {System.out.println ("--message--" +getmyspring ()); }     PublicString getmyspring () {returnmyspring; }     Public voidsetmyspring (String myspring) { This. myspring =myspring; }}

Testspring.java

 PackageCom.gdut.springdemo;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.FileSystemXmlApplicationContext; Public classtestspring { Public Static voidMain (string[] args) {ApplicationContext ctx=NewFilesystemxmlapplicationcontext ("Src/spring-demo.xml"); Spring Spring= (Spring) ctx.getbean ("Testbean");    Spring.show (); }}

Console printing:--message--this is my first spring!

Spring environment configuration under Eclipse

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.