• javaAop


    javaAop

    Maven

     
     
     
    xxxxxxxxxx
     
     
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.chexd</groupId>
        <artifactId>master</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>spring_test</module>
        </modules>
        <properties>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>5.3.3</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>5.3.3</version>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>1.8.9</version>
            </dependency>
        </dependencies>
     
     
    </project>
     

    xml设置

     
     
     
    xxxxxxxxxx
     
     
     
     
    <?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:p="http://www.springframework.org/schema/p"
           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/aop
           http://www.springframework.org/schema/aop/spring-aop.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd">
        <!--配置自动扫描包-->
        <context:component-scan base-package="com.chexd.spring"/>
        <aop:aspectj-autoproxy/>
    </beans>
     

    接口

     
     
     
     
     
     
     
     
    public interface UserDao {
        void add();
    }
     

    实现类

     
     
     
     
     
     
     
     
    @Component("user")
    public class User implements UserDao {
        public void add(){
            System.out.println("User的方法");
        }
    }
     

    切面

     
     
     
    xxxxxxxxxx
     
     
     
     
    @Aspect
    @Component
    public class UserAspect {
        @Before("execution(* com.chexd.spring.User.add(..))")
        public void aa(){
            System.out.println("发");
        }
    }
     

    测试类

     
     
     
    xxxxxxxxxx
     
     
     
     
        @Test
        public void testUser(){
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
            UserDao user = (UserDao) context.getBean("user");
            user.add();
        }
     
  • 相关阅读:
    png 的特点
    UIImangeView的用法
    uiTextView简单的用法
    UITextField简单的用法
    UIWindow的简单实用(二)
    UIView的简单实用
    objective-C 复合(组合)
    OC
    objective-C protocol协议
    object-C NSDate
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/14416047.html
Copyright © 2020-2023  润新知