Spring Boot read application.properties initialization bean

Source: Internet
Author: User

Application.properties

Bean1.hello = Hello ~bean2.name  = Namebean2.title = Titlebean3.info[name]    = namebean3.info[title]   = Titlebean3.info[age] =     agebean4.info[0] = name0bean4.info[1] = name1bean4.info[2] = name2bean4.info[3] = Name3

  

Beancontroller
@RestControllerpublic class Beancontroller {    @Value ("${bean1.hello}")    String bean1;    @Resource    Bean2 bean2;    @Resource    Bean3 bean3;    @Resource    Bean4 bean4;    @RequestMapping ("Bean1") public    String Bean1 () {        return bean1;    }    @RequestMapping ("bean2") public    Bean2 bean2 () {        return bean2;    }    @RequestMapping ("bean3") public    Bean3 bean3 () {        return bean3;    }    @RequestMapping ("Bean4") public    Bean4 Bean4 () {        return bean4;    }}

  

Bean2.java
@ConfigurationProperties (prefix = "bean2") @Componentpublic class Bean2 implements serializable{public    String Name ;    public String title;    Public String GetName () {        return name;    }    public void SetName (String name) {        this.name = name;    }    Public String GetTitle () {        return title;    }    public void Settitle (String title) {        this.title = title;    }}

  

Bean3.java
@ConfigurationProperties (prefix = "BEAN3") @Componentpublic class Bean3 implements serializable{    private map< String, string> info;    Public map<string, String> GetInfo () {        return info;    }    public void SetInfo (map<string, string> info) {        this.info = info;    }}

  

Bean4.java
@ConfigurationProperties (prefix = "Bean4") @Componentpublic class Bean4 implements serializable{    private list< string> info;    Public list<string> GetInfo () {        return info;    }    public void SetInfo (list<string> info) {        this.info = info;    }}

  



Spring Boot read application.properties initialization bean

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.