注解注入
- 注解:就是一个类,使用@注解名称
- 开发中:使用注解 取代 xml配置文件。
@Component :取代<bean class="">
@Component("id"):取代 <bean id="" class="">
web开发,提供3个@Component注解衍生注解(功能一样)取代<bean class="">
@Repository(“名称”):dao层
@Service(“名称”):service层
@Controller(“名称”):web层
@Autowired:自动根据类型注入
@Qualifier(“名称”):指定自动注入的id名称
@Resource(“名称”)
@ PostConstruct 自定义初始化
@ PreDestroy 自定义销毁
xml配置:
例一:
例二:
例三:
例四:
例五:
例六:
|