• -------------------------------------------------------------
  • ====================================

springboot的5种读取配置方式(5):通过applicationContext.xml读取

springcloud dewbay 5年前 (2019-04-12) 6680次浏览 已收录 0个评论 扫描二维码

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
版权声明:本文为博主原创文章,转载请附上博文链接!


露水湾 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springboot的5种读取配置方式(5):通过applicationContext.xml读取
喜欢 (17)
[]
分享 (0)
关于作者:
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址