锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲第一精品久久忘忧草社区,久久蜜桃一区二区,在线成人一区http://www.aygfsteel.com/musiclover/category/41030.htmlzh-cnThu, 17 Sep 2009 20:23:24 GMTThu, 17 Sep 2009 20:23:24 GMT60Spring AOP 瀛︿範絎旇http://www.aygfsteel.com/musiclover/archive/2009/08/23/292311.htmlJxiJxiSun, 23 Aug 2009 14:52:00 GMThttp://www.aygfsteel.com/musiclover/archive/2009/08/23/292311.htmlhttp://www.aygfsteel.com/musiclover/comments/292311.htmlhttp://www.aygfsteel.com/musiclover/archive/2009/08/23/292311.html#Feedback0http://www.aygfsteel.com/musiclover/comments/commentRss/292311.htmlhttp://www.aygfsteel.com/musiclover/services/trackbacks/292311.htmlAOP  Aspect Oriented Programing  闈㈠悜鏂歸潰緙栫▼
AOP 鏈
榪炴帴鐐?(Joinpoint)    紼嬪簭鎵ц鐨勭壒瀹氫綅緗?綾誨紑濮嬪垵濮嬪寲鍓嶃佺被鍒濆鍖栧悗銆佽皟鐢ㄥ墠鍚庛佸紓甯告姏鍑哄悗)
鍒囩偣:   (PointCut)     紼嬪簭綾諱腑瀹㈣瀛樺湪鐨勪簨鐗╋紙綾諱腑鐨勬柟娉曪級
澧炲己 :  (Advice)        緗叆鍒扮洰鏍囩被Joinpint鐨勪竴孌典唬鐮?br /> 鐩爣瀵硅薄:(Target)   寮曚粙(Introduction)  緇囧叆(Weaving)  浠g悊(Proxy) 鍒囬潰(Aspect):鍒囩偣鍜屽寮虹殑緇勬垚 
 
鍩虹鐭ヨ瘑: Spring Aop :浣跨敤鍔ㄦ佷唬鐞嗘妧鏈湪榪愯鏈熼棿緇囧叆澧炲己浠g爜
ProxyFactory 浠g悊宸ュ巶閲囩敤JDK浠g悊鎴朇GLib浠g悊鎶鏈?br /> JDK 鍔ㄦ佷唬鐞?
1.瀹氫箟UserService鎺ュ彛鍑芥暟:
public interface UserService {
public void addUser(int id);
 }

2.UserServiceImpl
public class UserServiceImpl implements UserService{
 
public void addUser(int id){
     System.out.println(
"娣誨姞涓涓敤鎴蜂腑 錛?/span>"+id);
 }

}

3.ProxyHandler
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;


public class ProxyHandler implements InvocationHandler{
   
private Object target;
   
public  ProxyHandler(Object target){
       
this.target=target;
   }

   
public Object invoke(Object proxy, Method method, Object[] args)
        
throws Throwable {
       System.out.println(
"娣誨姞鐢ㄦ埛鍓?/span>");
       Object obj
=method.invoke(target,args);
       System.out.println(
"娣誨姞鐢ㄦ埛鍚?/span>");
       
return obj;
}

}

TestProxyHandler
import java.lang.reflect.Proxy;

public class ProxyHandlerTest {
  
public static void main(String args[]){
      UserService target
=new UserServiceImpl();
      ProxyHandler handler
=new ProxyHandler(target);
      UserService proxy
=(UserService)Proxy.newProxyInstance(
        target.getClass().getClassLoader(),
        target.getClass().getInterfaces(),
        handler);
      proxy.addUser(
100);
  }

}

CGLib 浠g悊:
AddUserService鎺ュ彛:
package CGlib.Text.Service;

public interface AddUserService {
 
public void addUser(int id);
}

AddUserServiceImpl 瀹炵幇綾?
package CGlib.Text.Service;

public class AddUserServiceImpl implements AddUserService {

    
public void addUser(int id) {
        System.out.println(
"娣誨姞鐢ㄦ埛ID涓?"+id);
    }
}
CglibProxy 浠g悊綾?
package CGlib.Text.Service;



import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CglibProxy implements MethodInterceptor{
    
private Enhancer enhancer=new Enhancer();
    @SuppressWarnings(
"unchecked")
    
public Object getProxy(Class clazz){
        enhancer.setSuperclass(clazz);
        enhancer.setCallback(
this);
        
return enhancer.create();        
    }


    
public Object intercept(Object obj, Method method, Object[] args,
            MethodProxy proxy) 
throws Throwable {
        System.out.println(
"娣誨姞鐢ㄦ埛涔嬪墠");
        System.out.print(method.getName());
        System.out.print(obj.getClass().getName()
+"澶栧姞");
        System.out.print(args.getClass().getName());
        Object result
=proxy.invokeSuper(obj, args);
        System.out.println(
"澶栧姞鐨勫弬鏁?/span>"+args.toString());
        System.out.println(
"娣誨姞鐢ㄦ埛涔嬪悗");
        
// TODO Auto-generated method stub
        return result;
    }

    

}


CglibProxyTest:嫻嬭瘯綾?br />
package CGlib.Text.Service;

public class CglibProxyTest {
    
public static void main(String[] args){
        CglibProxy proxy
=new CglibProxy();
        AddUserServiceImpl userService
=
            (AddUserServiceImpl)proxy.getProxy(AddUserServiceImpl.
class);
      userService.addUser(
100);        
    }


}


瀵笿DK鍔ㄦ佷唬鐞嗗拰Cglib鍔ㄦ佷唬鐞嗙殑鐞嗚В錛?br /> JDK   浠g悊鏃舵ц兘楂橈紝浣嗙敓鎴愪唬鐞嗗璞℃椂榪愯鎬ц兘杈冧綆
Cglib 浠g悊鏃舵ц兘浣庯紝浣嗙敓鎴愪唬鐞嗗璞℃椂榪愯鎬ц兘杈冮珮
鎵浠ワ細鍗曚緥Singleton 鏃墮噰鐢–GLib浠g悊銆?br />


Jxi 2009-08-23 22:52 鍙戣〃璇勮
]]>
Spring http://www.aygfsteel.com/musiclover/archive/2009/07/25/288336.htmlJxiJxiSat, 25 Jul 2009 06:57:00 GMThttp://www.aygfsteel.com/musiclover/archive/2009/07/25/288336.htmlhttp://www.aygfsteel.com/musiclover/comments/288336.htmlhttp://www.aygfsteel.com/musiclover/archive/2009/07/25/288336.html#Feedback0http://www.aygfsteel.com/musiclover/comments/commentRss/288336.htmlhttp://www.aygfsteel.com/musiclover/services/trackbacks/288336.htmlSpring

Important 

Spring is an application framework. Unlike single-tier frameworks such as Struts or Hibernate, Spring aims to help structure whole applications in a consistent, productive manner, pulling together best-of-breed single-tier frameworks to create a coherent architecture.

Problems with the Traditional Approach to J2EE

浼犵粺J2EE鏂規硶瀛樺湪鐨勯棶棰?/span>

  • J2EE applications tend to contain excessive amounts of "plumbing" code.澶?/span>
  • Many J2EE applications use a distributed object model where this is inappropriate.鏉?/span>
  • The EJB component model is unduly complex.涓嶅綋
  • EJB is overused.榪囧害浣跨敤
  • Many "J2EE design patterns" are not, in fact, design patterns, but workarounds for technology limitations.鎶鏈窡涓嶄笂
  • J2EE applications are hard to unit test.嫻嬭瘯闅?/span>
  • Certain J2EE technologies have simply failed.

Enter Spring

鎺ヨЕSpring

  • Inversion of Control container:鍊掔疆鎺у埗
  • Aspect-Oriented Programming (AOP) framework:
  • Data access abstraction:
  • JDBC simplification:
  • Transaction management:
  • MVC web framework:
  • Simplification for working with JNDI, JTA, and other J2EE APIs:
  • Lightweight remoting:
  • JMS support:
  • JMX support:
  • Support for a comprehensive testing strategy for application developers:

The key Spring values can be summarized as follows:

·         Spring is a non-invasive framework.闈炰鏡鍏?

·         Spring provides a consistent programming model, usable in any environment.

·         Spring aims to promote code reuse.澶嶇敤

·         Spring aims to facilitate Object Oriented design in J2EE applications.

·         Spring aims to facilitate good programming practice, such as programming to interfaces, rather than classes.闈㈠悜鎺ュ彛

·         Spring promotes pluggability.鎬ц兘

·         Spring facilitates the extraction of configuration values from Java code into XML or properties files.

·         Spring is designed so that applications using it are as easy as possible to test.

·         Spring is consistent.

·         Spring promotes architectural choice.

·         Spring does not reinvent the wheel.



Jxi 2009-07-25 14:57 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 梅州市| 仪征市| 资阳市| 理塘县| 南丰县| 离岛区| 英超| 比如县| 德格县| 绥中县| 安达市| 邛崃市| 大荔县| 昭苏县| 甘南县| 梓潼县| 扶风县| 海兴县| 新兴县| 昌黎县| 淮安市| 渝北区| 临沧市| 堆龙德庆县| 志丹县| 安龙县| 平湖市| 长宁区| 镇坪县| 大安市| 华坪县| 芦山县| 怀来县| 嘉义县| 曲周县| 木兰县| 东阿县| 巴林右旗| 辽源市| 临澧县| 全南县|