spring注解01 bean xml配置文件注入

1.项目结构

项目结构图.png

1.1 pom.xml


       
           org.springframework
           spring-context
           5.1.3.RELEASE
       
       
           org.projectlombok
           lombok
           1.18.4
           provided
       
   

1.2 Person.java

@Data
public class Person {

    private String name;
    private int age;
    private String nickName;

    public Person(String name, int age, String nickName) {
        this.name = name;
        this.age = age;
        this.nickName = nickName;
    }
}

2,xml配置注入

2.1 beans.xml



    
        
        
        
    

2.2 测试类

public class MainTest {
    public static void main(String[] args) {
       final ClassPathXmlApplicationContext xmlApplicationContext = new ClassPathXmlApplicationContext("beans.xml");
       final Person person = (Person) xmlApplicationContext.getBean("person");
       System.out.println(person);
   }
}

2.3 测试结果

 com.tommy.MainTest
person = [Person(name=jm, age=16, nickName=tommy)]
person01

Process finished with exit code 0

你可能感兴趣的:(spring注解01 bean xml配置文件注入)