Springboot @PropertySource

Source: Internet
Author: User

@ConfigurationProperties (prefix= "person") load global profile application.properties or APPLICATION.YML by default

There are fields in the Application.properties file Persion.first-name

@PropertySource load profile information for the specified path

Application.properties Sibling directory has person.properties first-name such as read person.properties need to add @propertysource Note and specify the path @propertysource (value = {"Classpath:person.properties"})

Import org.springframework.boot.context.properties.ConfigurationProperties; Import Org.springframework.context.annotation.PropertySource; Import  = {"Classpath:person.properties" }) @ConfigurationProperties (prefix= "person")  publicclass person {    private  String firstName;             }

@ImportResource: Import the Spring configuration file and let the contents of the configuration file take effect (@importResource label on a configuration Class)

@ImportResource (location={"Classpath:xxx.xml"}) Import the spring configuration file for it to   take effect

@Configuration: Indicates that the current class is a configuration class, that is, to replace the previous spring configuration file, and to add components with <bean><bean/> tags in the configuration file

Springboot recommended ways to add components to a container: full annotation recommended

1. Configuration class equivalent to spring configuration file

2. Adding components to a container using @bean

Import Org.springframework.context.annotation.Bean; Import org.springframework.context.annotation.Configuration; @Configuration  Public class myappconfig {    // adds the return value of the method to the container; The default ID of this component in the container is the method name     @Bean       public HelloService HelloService () {        returnnew  HelloService ();}    } 

Springboot @PropertySource

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.