spring 设置注解依赖 @Required

@Required 是我们对必需要的东西进行注解,spring在运行时的时候会帮助我们检查依赖项是否存在。

其实现分两部:

1、在你的bean读经的model里面的相关属性加上@Required这个注解

2、在你的xml文件中做一些配置:

  a、引入 

xmlns:context="http://www.springframework.org/schema/context"

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

   b、如下操作

<beans>

<!--在这里添加你的-->

<context:annotation-config/>

</beans>

这样spring就会在运行的时候帮你检查required的项是否存在。

如果没有在bean.xml中添加<context:annotation-config/>  那么即使在你的model中定义了@Required注解的话,这个注解不会生效。

原文地址:https://www.cnblogs.com/codetime/p/6292482.html