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

高级 XML 配置

MVC 命名空间没有高级模式。如果您需要自定义无法更改的 bean 上的属性,则可以使用BeanPostProcessor生命周期弹簧钩ApplicationContext,如以下示例所示: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