zoukankan      html  css  js  c++  java
  • ideal 创建maven 项目

    一 准备工作,已经配置好了maven 环境 。没有的话,参考我的上一篇笔记。

    二,ideal相关配置

    打开ideal  找到设置。 file  ------->setting  。     点击进入。

    三,创建maven项目

    三, 演示导入jar包,cglib 代理   为例子。

    package com.ohs.cglib;
    
    /**
     *
     * cglib  代理的强大在于,就算没有接口实现,也能做代理
     *
     * 这里定义一个简单的水果类对象
     */
    public class Fruit {
        void  run1(){
            System.out.println("我是苹果");
        }
    
        void  run2(){
            System.out.println("我是香蕉");
        }
    
    }
    package com.ohs.cglib;
    import net.sf.cglib.proxy.Enhancer;
    import net.sf.cglib.proxy.MethodInterceptor;
    import net.sf.cglib.proxy.MethodProxy;
    import java.lang.reflect.Method;
    
    /**
     * 1.
     * 这里导入jar包的时候,我的电脑反应有点慢。等会就好了,不行就build 一下项目
     * 前提是确定在pom.XML 文件中已经有了 cglib的依赖
     *
     * 2.
     * 这就是水果的打理商。
     *
     *
     */
    public class FruitShopProxy implements MethodInterceptor {
    
        // 注入需要代理的对象
        private  Object object;
    
        public  Object getInstnce(Object object){
            this.object = object;
    
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(this.object.getClass());
    
            enhancer.setCallback(this);
            //创建真实的代理对象
            return enhancer.create();
        }
    
        public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
            System.out.println("开始卖水果了");
            methodProxy.invokeSuper(object,args);
            System.out.println("水果卖完了。");
            return null;
        }
    }

    package com.ohs.cglib;
    
    public class Test {
        public static void main(String[] args) {
            Fruit fruit = new Fruit();
    
            FruitShopProxy fruitShopProxy = new FruitShopProxy();
    
            //注意类型转换
            Fruit fruitShopProxyInstnce = (Fruit) fruitShopProxy.getInstnce(fruit);
    
            fruitShopProxyInstnce.run1();
        }
    }
  • 相关阅读:
    Sun开发的JINI技术在网络中的应用
    让memcached和mysql更好的工作
    Nginx+Tomcat+memcached负载均衡实现session共享
    Nginx 简单的负载均衡配置示例
    数据库sharding(scale up to scale out)
    docker专题(2):docker常用管理命令(上)
    UMDF
    编程精粹:编写高质量的C语言代码———笔记一
    子矩阵中共享1的最长对角线
    Print the numbers between 30 to 3000.
  • 原文地址:https://www.cnblogs.com/ZXF6/p/13714991.html
Copyright © 2011-2022 走看看