Configuration file of Springboot study notes (3) - @PropertySource annotation and @ImportResource annotation

1. @PropertySource annotation

@PropertySource: load the specified configuration file

If you put all the configurations in .properties or .yml, you may return to the fact that the configuration file is too large and the loading is too slow. At this time, you can create a new configuration file for some things that are not system configurations, and then use @PropertySource annotation to load . For example:

2. @ImportResource annotation

@ImportResource: Import the Spring configuration file to make the contents of the configuration file take effect;

There is no Spring configuration file in SpringBoot, and the configuration file we wrote ourselves cannot be recognized;

If you want Spring configuration to take effect, load it in, and mark @ImportResource on a configuration class, for example:

The configuration file is as follows:

 

At this time, you can access the corresponding file according to the id "helloService". 

 

Guess you like

Origin blog.csdn.net/dazhanglao/article/details/119606343