5.通过 application.xml 读取:
/**
- 学生实体类
- Created by ASUS on 2018/5/4
*/
@Component(“Student”)
public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public Student() {
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
/**
- springboot 启动类
*
*/
@SpringBootApplication
//读取 resources 目录下的 applicationContext.xml
@ImportResource(“classpath:applicationContext.xml”)
public class Application
{
public static void main( String[] args )
{
ApplicationContext applicationContext= SpringApplication.run(Application.class,args);
Student student= (Student) applicationContext.getBean(“student”,Student.class);
System.out.println(“message:”+student.toString());
}
}
applicationContext.xml 内容:
测试结果:
我的座右铭:不会,我可以学;落后,我可以追赶;跌倒,我可以站起来;我一定行。
作者:灰太狼 _cxh
来源:CSDN
原文:https://blog.csdn.net/weixin_39220472/article/details/80194217
版权声明:本文为博主原创文章,转载请附上博文链接!