Wenn ich eine Klasse wie folgt:Frühling Anmerkungen: Warum @Required funktioniert nicht, wenn Klasse @Autowired ist
public class MyConfig {
private Integer threshold;
@Required
public void setThreshold(Integer threshold) { this.threshold = threshold; }
}
Und ich benutze es wie folgt:
public class Trainer {
@Autowired
private MyConfig configuration;
public void setConfiguration(MyConfig configuration) { this.configuration = configuration; }
}
und initialisieren die Trainer in der xML-Kontext wie folgt:
<bean id="myConfiguration" class="com.xxx.config.MyConfig">
<!--<property name="threshold" value="33"/>-->
</bean>
Aus irgendeinem Grund die @Required Anmerkung gilt nicht, und der Kontext beginnt withou t ein Problem (Es sollte eine Ausnahme ausgelöst haben, die besagt, dass die Feldschwelle erforderlich ist ...).
Warum ist das ??
Überprüfen Sie, ob Sie 'RequiredAnnotationBeanPostProcessor' konfiguriert haben. Andernfalls wird '@ Required' nicht gescannt. – sura2k