MyEclipse2017 created Spring project for your reference. The specific content is as follows
1. Create a Web Project
2. Right-click on the project -->Properties
3. Search Spring -->Peoject Facets --> Find Spring on the right, check and save
4. Test
4.1 Create a class
package cn.spring.user;/*** * @author Dzsom* @date March 13, 2018 at 11:42:03 pm* @encoding UTF-8* @version 1.0 **/public class User { private String uname; private int age; public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }4.2 Modify the configuration file applicationContext.xml under src
<?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"> <!-- Leave the object to Spring management--> <bean name="user"></bean></beans>
4.3 Create a test class (@Test requires importing the junit package)
package cn.spring.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.spring.user.User;/*** * @author Dzsom* @date March 14, 2018 at 9:35:19 am* @encoding UTF-8* @version 1.0 **/public class Demo { @Test public void fun() { //1. Create container object ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml"); //2. Ask the container for object User user = (User) ac.getBean("user"); //3. Print System.out.println(user); }}4.4 Right-click to run the test. If there is a value output, the Spring will be successfully built.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.