Annotation Based

IoC  Annotation Based

标注组件的注解@org.springframework.stereotype.Repository
   专门用于标注数据访问组件
@org.springframework.stereotype.Service
   专门用于标注业务组件
@org.springframework.stereotype.Controller
   专门用于标注控制器组件
@org.springframework.stereotype.Component
   可以标注任意类型组件
标注作用域的注解@org.springframework.context.annotation.Scope
     singleton
     prototype
     request
     session
实现自动装配的注解@org.springframework.beans.factory.annotation.Autowired
   用于实现自动装配
   可以标注在需要自动装配的字段上,也可以是该字段对应的 setter 上
   默认根据类型进行自动装配
@org.springframework.beans.factory.annotation.Qualifier
   配合 Autowired 实现按照名称自动装配
   配合 Autowired 可以标注在需要自动装配的字段上,也可以是该字段对应的 setter 上

AOP  Annotation Based

标注切面类的注解

@org.aspectj.lang.annotation.Aspect
表示方位的注解
   
@org.aspectj.lang.annotation.Before
@org.aspectj.lang.annotation.Around
@org.aspectj.lang.annotation.AfterReturning
@org.aspectj.lang.annotation.AfterThrowing
@org.aspectj.lang.annotation.After

标注切点

@org.aspectj.lang.annotation.Pointcut

表示织入顺序

@org.springframework.core.annotation.Order

AOP的注解版

1.创建一个Student类,声明两个字段id,name

public class Student {

    private Integer id ; // object identifier filed
    private String name ; // student name

}

2.创建一个StudentDao类,用于被数据访问,作用域为singleton

// <bean id="studentDao" class="com.itlaobing.aop.annotation.dao.StudentDao"  scope="singleton" />
@Repository//标注组件的注解//专门用于标注数据访问组件
@Scope( "singleton" )//标注作用域为singleton的注解
public class StudentDao {

    public void persist(Student s ) {
        System.out.println( "保存 { id : " + s.getId() + ", name : " + s.getName() + " }" );
    }

}

3.创建一个StudentService类

// <bean id="studentService" class="com.itlaobing.aop.annotation.service.StudentService"  scope="singleton" />
@Service( "studentService" )//标注组件的注解//专门用于标注业务组件
public class StudentService {

    @Autowired
     //用于实现自动装配//可以标注在需要自动装配的字段上,也可以是该字段对应的 setter 上//默认根据类型进行自动装配
    private StudentDao studentDao ; // field

    public void save( Student s ) {
        System.out.println( "[ StudentService ] - [ save( Student ) ]" );
        studentDao.persist( s );
    }

    public StudentDao getStudentDao() {
        return studentDao;
    }

    public void setStudentDao(StudentDao studentDao) {
        System.out.println( "[ StudentService ] - [ setStudentDao ]" );
        this.studentDao = studentDao;
    }

}

4.创建一个StudentController类

// <bean id="studentController" class="com.itlaobing.aop.annotation.controller.StudentController"  scope="singleton" />
@Controller//专门用于标注控制器组件
public class StudentController {

    private StudentService studentService ;

    public void signUp(Student s ) {
        studentService.save( s );
    }

    public StudentService getStudentService() {
        return studentService;
    }

    //用于实现自动装配
    // 可以标注在需要自动装配的字段上,也可以是该字段对应的 setter 上
    // 默认根据类型进行自动装配
    @Autowired
    //配合 Autowired 实现按照名称自动装配
    //配合 Autowired 可以标注在需要自动装配的字段上,也可以是该字段对应的 setter 上
    @Qualifier( "studentService" )
    public void setStudentService(StudentService studentService) {
        System.out.println( "[ StudentController ] - [ setStudentService ]" );
        this.studentService = studentService;
    }

}

5.创建一个ServiceAspect类

@Component//可以标注任意类型组件
@Aspect//标注切面类的注解
public class ServiceAspect {

    @Pointcut( "execution(* com..service.*.save*(..))" )//标注切点
    private void servicePointcut(){
    }

    @Before( "servicePointcut()" )//切点方位
    public void before( JoinPoint joinPoint ) {
        System.out.println( "【 " + joinPoint.getSignature().getName() + " 】方法即将执行" );
    }

    @Around( "servicePointcut()" )//切点方位
    public Object around( ProceedingJoinPoint proceedingJoinPoint ) throws Throwable {

        String  name = proceedingJoinPoint.getSignature().getName();
        System.out.println( "开始为" + name + "计时" );
        long begin = System.nanoTime();

        Object result = proceedingJoinPoint.proceed();

        long end = System.nanoTime();
        System.out.print( "为" + name + "计时结束," );
        System.out.println( "[ " + name + " ]执行耗时 [ " + ( end - begin ) + "ns, ]" );

        return  result ;
    }

    @AfterReturning( pointcut = "servicePointcut()" , returning = "xxx")//切点方位
    public void afterReturn( JoinPoint joinPoint , Object xxx ) {
        System.out.println("【 " + joinPoint.getSignature().getName() + " 】方法执行后返回了 【 " + xxx +" 】");
    }

    @AfterThrowing( pointcut = "servicePointcut()" , throwing = "ex")//切点方位
    public void afterThrow( JoinPoint joinPoint , Throwable ex ) {
        System.out.println("【 " + joinPoint.getSignature().getName() + " 】方法执行执行时抛出 【 " + ex +" 】");
    }

    @After( "servicePointcut()" )//切点方位
    public void after( JoinPoint joinPoint ) {
        System.out.println( "【 " + joinPoint.getSignature().getName() + " 】方法执行结束" );
    }

}

 6.配置文件中添加context和aop命名空间,启用注解

<?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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       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
                            http://www.springframework.org/schema/aop
                            http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- 启用注解
    <context:annotation-config />
    -->

    <!-- 扫描 dao 包中所有的 所有的类  -->
    <context:component-scan base-package="com.itlaobing.aop.annotation.dao" />
    <!-- 扫描 service 包中所有的 所有的类  -->
    <context:component-scan base-package="com.itlaobing.aop.annotation.service" />
    <!-- 扫描 controller 包中所有的 所有的类  -->
    <context:component-scan base-package="com.itlaobing.aop.annotation.controller" />

    <!--  扫描 aspect 包-->
    <context:component-scan base-package="com.itlaobing.aop.annotation.aspect" />

    <!-- 告知容器需要为 注解 提供 自动代理支持  -->
    <aop:aspectj-autoproxy />

</beans>

 

7.创建AnnotationBasedAopTest测试类

  • 先指定配置文件,创建容器
  • 将配置文件放在容器里
  • 从容器中获得实例和实例对应的类
  • new一个Student对象,设置它的id和name
  • 调用 studentService的save方法
public class AnnotationBasedAopTest {

    public static void main(String[] args) {

        AbstractApplicationContext container = new ClassPathXmlApplicationContext( "classpath*:com/**/annotation/aop-annotation.xml" );

        StudentService studentService = container.getBean( "studentService" , StudentService.class);

        System.out.println( "Class ==> " + studentService.getClass() );

        Student s = new Student();
        s.setId( 1001 );
        s.setName( "奔波儿灞" );

        studentService.save( s );

        container.close();

    }

}

 

转载于:https://my.oschina.net/u/4045667/blog/2986782

数据治理是确保数据准确性、可靠性、安全性、可用性和完整性的体系和框架。它定义了组织内部如何使用、存储、保护和共享数据的规则和流程。数据治理的重要性随着数字化转型的加速而日益凸显,它能够提高决策效率、增强业务竞争力、降低风险,并促进业务创新。有效的数据治理体系可以确保数据在采集、存储、处理、共享和保护等环节的合规性和有效性。 数据质量管理是数据治理中的关键环节,它涉及数据质量评估、数据清洗、标准化和监控。高质量的数据能够提升业务决策的准确性,优化业务流程,并挖掘潜在的商业价值。随着大数据和人工智能技术的发展,数据质量管理在确保数据准确性和可靠性方面的作用愈发重要。企业需要建立完善的数据质量管理和校验机制,并通过数据清洗和标准化提高数据质量。 数据安全与隐私保护是数据治理中的另一个重要领域。随着数据量的快速增长和互联网技术的迅速发展,数据安全与隐私保护面临前所未有的挑战。企业需要加强数据安全与隐私保护的法律法规和技术手段,采用数据加密、脱敏和备份恢复等技术手段,以及加强培训和教育,提高安全意识和技能水平。 数据流程管理与监控是确保数据质量、提高数据利用率、保护数据安全的重要环节。有效的数据流程管理可以确保数据流程的合规性和高效性,而实时监控则有助于及时发现并解决潜在问题。企业需要设计合理的数据流程架构,制定详细的数据管理流程规范,并运用数据审计和可视化技术手段进行监控。 数据资产管理是将数据视为组织的重要资产,通过有效的管理和利用,为组织带来经济价值。数据资产管理涵盖数据的整个生命周期,包括数据的创建、存储、处理、共享、使用和保护。它面临的挑战包括数据量的快速增长、数据类型的多样化和数据更新的迅速性。组织需要建立完善的数据管理体系,提高数据处理和分析能力,以应对这些挑战。同时,数据资产的分类与评估、共享与使用规范也是数据资产管理的重要组成部分,需要制定合理的标准和规范,确保数据共享的安全性和隐私保护,以及建立合理的利益分配和权益保障机制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值