pom.xml
4.0.0 org.example Spring011.0-SNAPSHOT Spring01 http://www.example.com UTF-8 1.8 1.8 junit junit4.12 test org.springframework spring-context5.2.4.RELEASE org.junit.jupiter junit-jupiterRELEASE compile junit junit4.13.2 org.eclipse.jetty jetty-maven-plugin9.4.15.v20190215
spring.xml
目录卡结构:
User.java类
package com.cx.bean;
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public User() {
}
public User(Integer id, String username, String password) {
this.id = id;
this.username = username;
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + ''' +
", password='" + password + ''' +
'}';
}
}
测试类:
package com.cx.test;
import com.cx.bean.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UserTest {
@Test
public void userTest() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
User user = (User)applicationContext.getBean("user");
System.out.println(user);
}
}
巡行截图:



