懒得笔记4 spring annotation
2015-08-13 19:14
435 查看
1, 要加入 aop 包, 不然会报
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [beans.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
2,xml 文档
3,注解
1,@Autowired
按类型再按名字@qualifier
在setter之前标志(As expected, you can apply the
to "traditional" setter methods:)
2,@Required
This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws an exception if the affected bean property
has not been populated; this allows for eager and explicit failure, avoiding NullPointerExceptions or the like later on. It is still recommended that you put assertions into the bean class itself, for example, into an init method. Doing so enforces those required
references and values even when you use the class outside of a container.
仅仅在配置时就用于检测是否有合适的值与bean配置。防止出现NullPointerExceptions
3,@Resource(name="UserDAO")
按名字再按类型
4,@component
在xml中加入以下这句话,便可以不用在xml里定义 bean 系统自动到指定的地方去扫描找到对应的bean,写在对应的类里
<context:component-scan base-package="com.bjsxt"/>
在bean中加入 @Component("u") 来指定bean 的id 也可不写,默认为类名小写
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [beans.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
2,xml 文档
<?xml version="1.0" encoding="UTF-8"?> <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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> </beans>
3,注解
1,@Autowired
按类型再按名字@qualifier
在setter之前标志(As expected, you can apply the
@Autowiredannotation
to "traditional" setter methods:)
2,@Required
This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws an exception if the affected bean property
has not been populated; this allows for eager and explicit failure, avoiding NullPointerExceptions or the like later on. It is still recommended that you put assertions into the bean class itself, for example, into an init method. Doing so enforces those required
references and values even when you use the class outside of a container.
仅仅在配置时就用于检测是否有合适的值与bean配置。防止出现NullPointerExceptions
3,@Resource(name="UserDAO")
按名字再按类型
4,@component
在xml中加入以下这句话,便可以不用在xml里定义 bean 系统自动到指定的地方去扫描找到对应的bean,写在对应的类里
<context:component-scan base-package="com.bjsxt"/>
在bean中加入 @Component("u") 来指定bean 的id 也可不写,默认为类名小写
相关文章推荐
- [Java] Majority Element II 找众数2
- eclipse启动报错A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse.
- 深入理解java的finalize
- Eclipse ADT的Custom debug keystore所需证书规格
- [Java] Majority Element (求过半数,或者翻译成 求出现次数过半的众数)
- Java的反射机制
- 修改eclipse默认workspace
- 【Head First Java 读书笔记】(三)primitive主数据类型和引用
- java dom解析xml
- (转)Eclipse快捷键
- Java中Filter、Servlet、Listener
- Java SE 学习笔记(二)
- java两个线程打印奇数和偶数
- Eclipse远程调试java web应用
- java大数 hdu5241
- Java之LinkedHashSet
- Eclipse操作hive数据库以及操作HDFS的jar包和环境配置
- Java之HashSet
- Java之HashMap
- Java 学习笔记(1) -- 名词解释