TZ_05_Spring_annotation配置

1.用annotation配置文件开发要明确告诉Spring框架我们是注解开发

  版本spring-context 5.0.2

  配置ApplicationContext.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
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">


    <!--告诉spring在创建容器时需要扫描的包  配置context-->
    <context:component-scan base-package="com.hdh"></context:component-scan>
</beans>

 

 

2.常见注解的作用和用法

<bean id="accountService" class="com.hdh.service.impl" scope="" init-method="" destory-method=""><property name="" value="" | ref=""></property></bean>
 * 
 *  注解也是用于创建对象的
 *        他们的作用就和在xml配置文件中编写一个<bean>标签是一样的
 *    @Componcet :用于把当前类对象放入spring容器中
 *    属性:value:用于指定bean的id。不写时默认是当前类名加上首字母小写
 *    
 *    @Controller:表现层
 *    @Service:业务层
 *    @Repository:持久层
 *    以上三个注解他们的作用和属性与Componcet一摸一样
 *    他们三个是Spring框架为我们明确提供为三层使用的
 *    
 */

 

转载于:https://www.cnblogs.com/asndxj/p/11323393.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值