本文整理汇总了Java中org.springframework.aop.aspectj.annotation.AspectJProxyFactory.getProxy方法的典型用法代码示例。如果您正苦于以下问题:Java AspectJProxyFactory.getProxy方法的具体用法?Java AspectJProxyFactory.getProxy怎么用?Java AspectJProxyFactory.getProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.aop.aspectj.annotation.AspectJProxyFactory
的用法示例。
在下文中一共展示了AspectJProxyFactory.getProxy方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testProgrammaticProxyCreation
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
@Test
public void testProgrammaticProxyCreation() {
ITestBean testBean = new TestBean();
AspectJProxyFactory factory = new AspectJProxyFactory();
factory.setTarget(testBean);
CounterAspect myCounterAspect = new CounterAspect();
factory.addAspect(myCounterAspect);
ITestBean proxyTestBean = factory.getProxy();
assertTrue("Expected a proxy", proxyTestBean instanceof Advised);
proxyTestBean.setAge(20);
assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
}
示例2: aopAspectJ
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
public static void aopAspectJ() {
// 基于编程方式的AspectJ织入
AspectJProxyFactory weaver = new AspectJProxyFactory();
weaver.setProxyTargetClass(true);
weaver.setTarget(new Foo());
weaver.addAspect(PerformanceTraceAspect.class);
Object proxy = weaver.getProxy();
((Foo) proxy).method1();
((Foo) proxy).method2();
// 自动代理织入,参见spring-appfx-aop2.xml
ApplicationContext app = iocInit("");
proxy = app.getBean("fooTarget");
((Foo) proxy).method1();
((Foo) proxy).method2();
// 基于XSD形式的自动代理,参见配置文件
}
示例3: test
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
@Test
public void test() {
Intf target = new Impl();
AspectJProxyFactory factory = new AspectJProxyFactory(target);
MyAspect aspect = new MyAspect();
factory.addAspect(aspect);
Intf proxy = factory.getProxy();
Assert.assertEquals(Impl.class, BeanUtils.getImplClassFromBean(proxy));
Assert.assertEquals(Impl.class, BeanUtils.getImplClassFromBean(new Impl()));
}
示例4: setUp
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
mockAbilitiesService = mock(AbilitiesService.class);
RequestLogger requestLogger = new RequestLogger();
AbilitiesController abilitiesController = new AbilitiesController(mockAbilitiesService);
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(abilitiesController);
proxyFactory.addAspect(requestLogger);
proxyController = proxyFactory.getProxy();
LogSession.start();
}
示例5: setUp
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
/**
* SetUp.
* @throws Exception - if something is wrong this exception is thrown.
*/
@Before
public void setUp() throws Exception {
testHelper = new TestHelper();
securityManager = new MockSecurityManager();
storage = new MockDaoStorage();
contentDao = new MockContentDao(storage);
userDao = new MockUserDao(storage);
service = new StandardContentService();
lockManager = new SingleVMLockManager();
service.setContentDao(contentDao);
service.setLockManager(lockManager);
service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
service.init();
// create a factory that can generate a proxy for the given target object
AspectJProxyFactory factory = new AspectJProxyFactory(service);
sa.setSecurityManager(securityManager);
sa.setContentDao(contentDao);
sa.setUserDao(userDao);
//this bean has request scope
//sa.setSecuredMethod(Proxy) should be called by Spring
sa.init();
factory.addAspect(sa);
// now get the proxy object...
proxyService = factory.getProxy();
}
示例6: createProxyServiceWithoutExpectedAdviceExecution
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
/**
* Create service with the advice. It is not expected to create eventData for handers because they
* won't execute.
*/
private void createProxyServiceWithoutExpectedAdviceExecution() {
eventOperationExtensionsAdvice = new ContextServiceExtensionsAdvice(){
};
// create a factory that can generate a proxy for the given target object
AspectJProxyFactory factory = new AspectJProxyFactory(service);
factory.addAspect(eventOperationExtensionsAdvice);
// now get the proxy object...
proxyService = factory.getProxy();
}
示例7: createProxyServiceWithExpectedAdviceExecution
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
/**
* Create service with the advice. The handlers wll execure with expected results.
*/
private void createProxyServiceWithExpectedAdviceExecution() {
eventOperationExtensionsAdvice = new ContextServiceExtensionsAdvice();
// create a factory that can generate a proxy for the given target object
AspectJProxyFactory factory = new AspectJProxyFactory(service);
factory.addAspect(eventOperationExtensionsAdvice);
// now get the proxy object...
proxyService = factory.getProxy();
}
示例8: setUp
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
/**
* SetUp.
* @throws Exception - if something is wrong this exception is thrown.
*/
@Before
public void setUp() throws Exception {
testHelper = new TestHelper();
securityManager = new MockSecurityManager();
storage = new MockDaoStorage();
calendarDao = new MockCalendarDao(storage);
contentDao = new MockContentDao(storage);
eventLogDao = new MockEventLogDao();
service = new StandardContentService();
lockManager = new SingleVMLockManager();
service.setContentDao(contentDao);
service.setLockManager(lockManager);
service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
service.init();
// create a factory that can generate a proxy for the given target object
AspectJProxyFactory factory = new AspectJProxyFactory(service);
// add aspect
EventLogAdvice eva = new EventLogAdvice();
eva.setEnabled(true);
eva.setSecurityManager(securityManager);
eva.setEventLogDao(eventLogDao);
eva.init();
factory.addAspect(eva);
// now get the proxy object...
proxyService = factory.getProxy();
}
示例9: timeMethod
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
@Test
public void timeMethod() throws Exception {
Timeable cprime = new TestClass();
AspectJProxyFactory factory = new AspectJProxyFactory(cprime);
factory.addAspect(MethodTimer.class);
Timeable proxy = factory.getProxy();
proxy.timeMe();
final Double tot = CollectorRegistry.defaultRegistry.getSampleValue("test_class_sum");
Assert.assertNotNull(tot);
assertEquals(0.02, tot, 0.01);
}
示例10: getProxy
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
<T> T getProxy(T source){
AspectJProxyFactory factory = new AspectJProxyFactory(source);
factory.addAspect(MethodTimer.class);
return factory.getProxy();
}
示例11: main
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory; //导入方法依赖的package包/类
public static void main( String[] args )
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Student student = (Student) context.getBean("student");
AspectJProxyFactory factory = new AspectJProxyFactory(student);
factory.addAspect(Logging.class);
Student studentProxy = factory.getProxy();
studentProxy.getName();
}