ClassPathXmlApplicationContext如何设置必填属性
- 解释
- 例子
- 测试结果
-
- requiredPropertiesIsEmptyTest测试结果
- requiredPropertiesIsNotEmptyTest测试结果![requiredPropertiesIsNotEmptyTest测试结果图](https://img-blog.csdnimg.cn/20210709114935221.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MjQ2MDE2,size_16,color_FFFFFF,t_70)
- 结果解释
解释
在某些特定的场景中,需要满足一定条件才允许进行Spring初始化操作。
例子
我们使用一个案例来解释
(1)继承ClassPathXmlApplicationContext的自定义类
public class CustomClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
@Override
protected void initPropertySources() {
super.initPropertySources();
getEnvironment().setRequiredProperties(