The spring framework under the Eclipse IDE uses a simple instance

Source: Internet
Author: User
Tags getmessage

The spring framework under the Eclipse IDE uses a simple instance


1 preparation
Java JDK installation.

Eclipse Software Installation.
Depending on the system installation version 32/64, select Eclipse IDE for Java developers to install online.

Spring Framework Download.

commons_logging Package Download

2 Configuration work
Right-click on the project bar, build path->config build Path Select Librarys, Add External jars Import the spring and commons_logging jar packages

3 Sample Programs
Create the COM.MANONGJC package under the SRC folder, creating the HelloWorld class and the Mainapp class separately in the package, with the following code:

HelloWorld class
Package COM.MANONGJC;

public class HelloWorld {
Private String message;

public void Setmessage (String message) {
this.message = message;
}

public void GetMessage () {
SYSTEM.OUT.PRINTLN ("Your message:" + message);
}
}

Mainapp class
Package COM.MANONGJC;

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

public class Mainapp {
public static void Main (string[] args) {
ApplicationContext context =
New Classpathxmlapplicationcontext ("Beans.xml");

HelloWorld obj = (HelloWorld) context.getbean ("HelloWorld");

Obj.getmessage ();
}
}

Under the SRC folder, create the Beans.xml file with the following code:

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

<bean id= "HelloWorld" class= "Com.manongjc.HelloWorld" >
<property name= "message" value= "Hello world!" />
</bean>

</beans>

Select Mainapp, click Run, you can see the output log in the console.

The spring framework under the Eclipse IDE uses a simple instance

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.