Spring framework configuration and simple instances under the latest Eclipse IDE, eclipsespring

Source: Internet
Author: User

Spring framework configuration and simple instances under the latest Eclipse IDE, eclipsespring
Some time ago, I started to learn the Spring framework. I bought books and read videos to find tutorials. However, I rarely introduced how to configure Spring + Eclipse. Now I will share my successful experiences with you. Some of the source code of this article comes from the Code agricultural Tutorial: http://www.manongjc.com/spring/spring_environment_setup.html in the text is not correct, please correctI. preparations:① Install Java jdk.Click JDK download at http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html.For more information about environment variables, see other online tutorials. Http://jingyan.baidu.com/article/db55b609ab421f4ba30a2f04.html② Install Eclipse software.Http://www.eclipse.org/downloads /. The latest version is eclipse neon. Select the 32/64-bit version based on your local machine.Open the eclipse-inst-win. Program and select the first item: Eclipse IDE for Java Developers for online installation.
③ Download the Spring framework.        Http://repo.spring.io/release/org/springframework/spring/4.3.3.RELEASE/ I use the latest version 4.3.3 here, previous versions can be downloaded on the previous page of the website. Download the first one. Just download the dist.zip file.④ Download the Commons_Logging package.Click commons-logging-1.2-bin.zip under binariesto download the http://commons.apache.org/proper/commons-logging/download_logging.cgi.Ii. Configuration:Unzip the jar files in the/libdirectory, and choose the commons-logging-1.2.jar files in the commons-logging-1.2-bin.zip directory. Now, Environment configuration is complete. 3. simple instance: Create the com. manongjc package in the src folder, and create the HelloWorld class and MainApp class respectively in the package. The Code is as follows:

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);   }}
 

 

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();   }}
 

 

Create the beans. xml file in the src folder. The Code is as follows:
 1 <?xml version="1.0" encoding="UTF-8"?> 2  3 <beans xmlns="http://www.springframework.org/schema/beans" 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5     xsi:schemaLocation="http://www.springframework.org/schema/beans 6     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 7  8    <bean id="helloWorld" class="com.manongjc.HelloWorld"> 9        <property name="message" value="Hello World!"/>10    </bean>11 12 </beans>
 

 

Run the command in explanation. The console outputs: Your Message: Hello World! I hope this article will help you. If you need to repost it, please indicate the source, love sharing, and reject it. The blog spirit will last forever-cvrigo

15:01:18

 

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.