对于最新的稳定版本,请使用 Spring Framework 7.0.6!spring-doc.cadn.net.cn

高级XML配置

MVC命名空间没有高级模式。如果你需要自定义一个无法通过其他方式更改的bean上的属性,可以使用Spring ApplicationContextBeanPostProcessor 生命周期钩子,如下例所示:spring-doc.cadn.net.cn

@Component
public class MyPostProcessor implements BeanPostProcessor {

	public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
		// ...
	}
}
@Component
class MyPostProcessor : BeanPostProcessor {

	override fun postProcessBeforeInitialization(bean: Any, name: String): Any {
		// ...
	}
}

请注意,您需要将MyPostProcessor声明为一个bean,要么在XML中显式声明,要么通过<component-scan/>声明让其被检测到。spring-doc.cadn.net.cn