ConditionalOnProperty(name = "ConditionalOnProperty ", havingValue =" ConditionalOnProperty ", MatchIfMissing = false) #name=" attribute name "#havingValue=" attribute value" #matchIfMissing=true or false,true This annotation will inject the bean if the value of the property is equal to the value in havingValue, so it is the same as @bean, @compant The following is the configuration of the properties in my yML file. My application-prod.yml server. Port is 28080. In application-prod.yml, server.port is 11111.Copy the code
server:  
    port: 28080Copy the code
I used this @conditionalonProperty when I configured scheduled tasks. Here's how it works in my code:Copy the code
@Component
@ConditionalOnProperty(name = "server.port", havingValue = "28080", matchIfMissing = false)
public class AllowanceTask {}Copy the code