Spring学习(十一)-----Spring使用@Required注解依赖检查
@Required示例
package com.yiibai.common; import org.springframework.beans.factory.annotation.Required; public class Customer
{
private Person person;
private int type;
private String action; public Person getPerson() {
return person;
}
@Required
public void setPerson(Person person) {
this.person = person;
}
}
1. 包函 <context:annotation-config />
<beans
...
xmlns:context="http://www.springframework.org/schema/context"
...
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
...
<context:annotation-config />
...
</beans>
完整的实例,
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config /> <bean id="CustomerBean" class="com.yiibai.common.Customer">
<property name="action" value="buy" />
<property name="type" value="1" />
</bean> <bean id="PersonBean" class="com.yiibai.common.Person">
<property name="name" value="yiibai" />
<property name="address" value="address ABC" />
<property name="age" value="29" />
</bean> </beans>
2. 包函 RequiredAnnotationBeanPostProcessor
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean
class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> <bean id="CustomerBean" class="com.yiibai.common.Customer">
<property name="action" value="buy" />
<property name="type" value="1" />
</bean> <bean id="PersonBean" class="com.yiibai.common.Person">
<property name="name" value="yiibai" />
<property name="address" value="address ABC" />
<property name="age" value="29" />
</bean>
</beans>
org.springframework.beans.factory.BeanInitializationException:
Property 'person' is required for bean 'CustomerBean'
定义@Required
Spring学习(十一)-----Spring使用@Required注解依赖检查的更多相关文章
- Spring使用@Required注解依赖检查
Spring依赖检查 bean 配置文件用于确定的特定类型(基本,集合或对象)的所有属性被设置.在大多数情况下,你只需要确保特定属性已经设置但不是所有属性.. 对于这种情况,你需要 @Required ...
- Spring学习(7)--- @Required注解
@Required注解是用于bean属性的setter方法 这个注解仅仅表示,受影响的bean属性必须在配置时被填充,通过在bean定义胡通过自动装配一个明确的属性值 package com.mypa ...
- Spring学习(六)-----Spring使用@Autowired注解自动装配
Spring使用@Autowired注解自动装配 在上一篇 Spring学习(三)-----Spring自动装配Beans示例中,它会匹配当前Spring容器任何bean的属性自动装配.在大多数情况下 ...
- spring学习12 -Spring 框架模块以及面试常见问题注解等
以下为spring常见面试问题: 1.Spring 框架中都用到了哪些设计模式? Spring框架中使用到了大量的设计模式,下面列举了比较有代表性的: 代理模式—在AOP和remoting中被用的比较 ...
- Spring学习笔记(14)——注解零配置
我们在以前学习 Spring 的时候,其所有的配置信息都写在 applicationContext.xml 里,大致示例如下: java代码: <beans> <bean n ...
- Spring学习(十)-----Spring依赖检查
在Spring中,可以使用依赖检查功能,以确保所要求的属性可设置或者注入. 依赖检查模式 4个依赖检查支持的模式: none – 没有依赖检查,这是默认的模式. simple – 如果基本类型(int ...
- Spring学习(8)--- @Autowired注解(一)
可以将@Autowired注解为“传统”的setter方法 package com.mypackage; import org.springframework.beans.factory.annota ...
- spring学习(三) ———— spring事务操作
前面一篇博文讲解了什么是AOP.学会了写AOP的实现,但是并没有实际运用起来,这一篇博文就算是对AOP技术应用的进阶把,重点是事务的处理. --wh 一.jdbcTemplate 什么是JdbcTem ...
- Spring学习笔记—Spring之旅
1.Spring简介 Spring是一个开源框架,最早由Rod Johnson创建,并在<Expert One-on-One:J2EE Design and Development> ...
随机推荐
- HDU 2544最短路 (迪杰斯特拉算法)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2544 最短路 Time Limit: 5000/1000 MS (Java/Others) Me ...
- EF中的Guid主键
除了自增长ID(int),我们还能把主键设置为GUID类型的. 创建我们的数据表 CREATE TABLE dbo.JoinA( AGUID UNIQUEIDENTIFIER PRIMARY KEY ...
- goldengate简单配置
goldendate配置单项同步 源数据库 extract抽取进程 trail文件 复制进程 目标进程 由于最开始配置goldengate的时候,没有弄清除原理,导致出错了都不知道怎么解决. 最 ...
- GoogleTest初探(2)
前面的随笔介绍了Google Test中的基本测试单元TEST和测试夹具TEST_F,此篇介绍区别于这两种测试的参数化测试TEST_P 当待测试方法的行为取决于传入的参数时,而且这些参数的不同组合有多 ...
- BZOJ 2654: tree(二分 最小生成树)
Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 2901 Solved: 1196[Submit][Status][Discuss] Descript ...
- MySQL->元数据[20180510]
MySQL元数据 Meta Data,一般是结构化数据(如存储在数据库里的数据,字段长度.类型.默认值等等).Meta Data就是描述数据的数据,在MySQL中描述有哪些数据库.哪些表.表有 ...
- ElasticSearch优化系列五:机器设置(硬盘、CPU)
硬盘对集群非常重要,特别是建索引多的情况.磁盘是一个服务器最慢的系统,对于写比较重的集群,磁盘很容易成为集群的瓶颈. 如果可以承担的器SSD盘,最好使用SSD盘.如果使用SSD,最好调整I/O调度算法 ...
- 执行mongod其他实例出现的问题
windows环境下,配置其他mongo实例,会出现一些问题 1.配置路径不对,执行bat文件时出现闪屏 根据提示创建C:\data\db\ 目录(因为mongodb默认在/data/db下创建数据库 ...
- 树莓3B+_Raspbian 源使用帮助
https://mirrors.ustc.edu.cn/help/raspbian.html Raspbian 源使用帮助 地址 https://mirrors.ustc.edu.cn/raspb ...
- mitmproxy 在windows上的使用
mitmproxy 是一个中间件代理, 结合python使用 安装 pip install mitmproxy 在windows上没有mitmproxy 所以只要用mitmdump和mitmwdb ...