Spring 4 ha due nuove annotazioni @Condition
e @ConfigurationConditon
per controllare se un bean viene aggiunto al contesto dell'applicazione Spring. JavaDoc non fornisce abbastanza contesto/quadro generale per comprendere i casi d'uso di @ConfigurationCondition
.Quando utilizzare Spring @ConfigurationCondition vs @Condition?
Quando utilizzare @ConfigurationCondition
rispetto a @Condition
?
public interface ConfigurationCondition extends Condition {
/**
* Returns the {@link ConfigurationPhase} in which the condition should be evaluated.
*/
ConfigurationPhase getConfigurationPhase();
/**
* The various configuration phases where the condition could be evaluated.
*/
public static enum ConfigurationPhase {
/**
* The {@link Condition} should be evaluated as a {@code @Configuration} class is
* being parsed.
*
* <p>If the condition does not match at this point the {@code @Configuration}
* class will not be added.
*/
PARSE_CONFIGURATION,
/**
* The {@link Condition} should be evaluated when adding a regular (non
* {@code @Configuration}) bean. The condition will not prevent
* {@code @Configuration} classes from being added.
*
* <p>At the time that the condition is evaluated all {@code @Configuration}s
* will have been parsed.
*/
REGISTER_BEAN
}
}
Potresti approfondire il significato delle due diverse fasi. Queste fasi sono diverse dalle fasi del ciclo di vita dell'inizializzazione del bean in cui vengono eseguiti i diversi post processor? – ams
ha aggiornato la mia risposta. –