Java框架:Sping框架:注解开发

开发中使用注解 取代 xml配置文件

  • @Component     取代 <bean class="">
  • @Component("id") 取代 <bean id="" class="">

web开发中提供3个@Component注解衍生注解(功能一样)

  1. @Repository("beanID(名)"):   dao层
  2. @Service("beanID(名)"):         service层
  3. @Controller("beanID(名)"):    web层

常用注解

  • @Autowired:            自动 根据   类型  注入
  • @Qualifier("beanID(名)"):指定自动注入的id名称
  • @Resource("beanID(名)")   == =  @Autowired+@Qualifier("beanID(名)") 
  • @scope("prototype")   不写默认单例
  • @ PostConstruct 自定义初始化
  • @ PreDestroy 自定义销毁

Spring开启注解 :   xml文件配置

<?xml version="1.0" encoding="UTF-8"?>
<!--xmlns xml namespace:xml命名空间-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p ="http://www.springframework.org/schema/p"
       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/>

    <!-- 注解扫描包位置-->
    <context:component-scan base-package="com.zjc.包名--扫描路径"/>

</beans>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值