# spring boot Configuration

## 配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效

[配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效](https://blog.csdn.net/dalangzhonghangxing/article/details/78420057)

```java
@Configuration
@AutoConfigureBefore({NotifierListenerConfiguration.class,CompositeNotifierConfiguration.class})
public class EmailNotifierConfiguration {

    @Bean
    @ConditionalOnMissingBean
    // @ConditionalOnProperty("admin.notify.email.to")
    @ConditionalOnProperty(value="admin.notify.email.to", havingValue = "true")
    public EmailNotifier mailNotifier() {
        return new EmailNotifier();
    }

    @ConfigurationProperties("admin.notify.email")
    public class EmailNotifier extends AbstractStatusChangeNotifier {
        private String to[];
        private String cc[];
        @Override
        protected void doNotify(ClientApplicationEvent event) throws Exception {
            System.out.println("XXXXX");
        }

        public String[] getTo() {
            return to;
        }

        public void setTo(String[] to) {
            this.to = to;
        }

        public String[] getCc() {
            return cc;
        }

        public void setCc(String[] cc) {
            this.cc = cc;
        }
    }
}
```

`properties application.properties admin.notify.email.to=aa admin.notify.email.cc=bb`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/springboot/springboot-zhi-configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
