Article From:https://www.cnblogs.com/black-/p/9072121.html

8.1 Main lists @PropertySource and Environment

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("classpath:/app.properties")
public class ExpressiveConfig {
    @Autowired
    private Environment environment;

    @Bean
    public A a(){
        new A(environment.getProperty("a.name"));
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *