@Autowired注解的使用方法


@Autowired是Spring提供的一种注入Bean的方法。
具体的应用是:
1)在Service类中定义的注入属性前加@Autowired。例如:@Autowired private PersonDAO personDAO,
2)必须有个set方法,例如:
@Autowired
public void setPersonDAO(PersonDAO personDAO) {
System.out.println("********** @Autowired注入Bean *************");
this.personDAO = personDAO;
}
Spring配置文件的配置内容:
1) 头部
(加入)xmlns:context="http://www.springframework.org/schema/context
(添加)xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
2) 
<context:annotation-config/>
<bean id="personDAO" class="edu.syict.dao.impl.PersonDAOImpl"/>
<bean id="personService" class="edu.syict.service.impl.PersonServiceImpl"/>
有问题发信息。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM