org.springframework.aop.scope.ScopedObject Java Examples
The following examples show how to use
org.springframework.aop.scope.ScopedObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThreadScopeTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testThreadScope() throws Exception { // verify that set/get works in normal case threadedService.setValue(VALUE_FIRST); Assert.assertEquals(VALUE_FIRST, threadedService.getValue()); // assure bean is not treated as prototype ThreadedService ts = applicationContext.getBean(BEAN_NAME, ThreadedService.class); Assert.assertEquals(VALUE_FIRST, ts.getValue()); Thread thread = new Thread(new Runnable() { public void run() { // we are in the thread, now create the autowired class and test: testInOtherThread(); } }); thread.start(); thread.join(); // now verify that we can clear the thread data Assert.assertEquals(VALUE_FIRST, threadedService.getValue()); ((ScopedObject)threadedService).removeFromScope(); Assert.assertNull(threadedService.getValue()); }
Example #2
Source File: ScopedBeanInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void interceptorWithCglibProxy() throws Exception { final Object realObject = new Object(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTarget(realObject); proxyFactory.setProxyTargetClass(true); final Object proxy = proxyFactory.getProxy(); ScopedObject scoped = new ScopedObject() { @Override public Object getTargetObject() { return proxy; } @Override public void removeFromScope() { // do nothing } }; assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped)); }
Example #3
Source File: ScopedBeanInterceptorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void interceptorWithPlainObject() throws Exception { final Object realObject = new Object(); ScopedObject scoped = new ScopedObject() { @Override public Object getTargetObject() { return realObject; } @Override public void removeFromScope() { // do nothing } }; // default contract is to return null for default behavior assertNull(interceptor.getEntityName(realObject)); assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped)); }
Example #4
Source File: ScopedBeanInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public String getEntityName(Object entity) { if (entity instanceof ScopedObject) { // Determine underlying object's type. Object targetObject = ((ScopedObject) entity).getTargetObject(); return AopUtils.getTargetClass(targetObject).getName(); } // Any other object: delegate to the default implementation. return super.getEntityName(entity); }
Example #5
Source File: TransactionSynchronizationUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
public static Object unwrapIfNecessary(Object resource) { if (resource instanceof ScopedObject) { return ((ScopedObject) resource).getTargetObject(); } else { return resource; } }
Example #6
Source File: ScopedBeanInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public String getEntityName(Object entity) { if (entity instanceof ScopedObject) { // Determine underlying object's type. Object targetObject = ((ScopedObject) entity).getTargetObject(); return AopUtils.getTargetClass(targetObject).getName(); } // Any other object: delegate to the default implementation. return super.getEntityName(entity); }
Example #7
Source File: ScopingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testRawScopes() throws Exception { String beanName = "scopedProxyInterface"; // get hidden bean Object bean = ctx.getBean("scopedTarget." + beanName); assertFalse(bean instanceof ScopedObject); }
Example #8
Source File: ConfigurationClassPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void scopedProxyTargetMarkedAsNonAutowireCandidate() { AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(bpp); beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class)); beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class)); ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); pp.postProcessBeanFactory(beanFactory); ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean; assertTrue(injected instanceof ScopedObject); assertSame(beanFactory.getBean("scopedClass"), injected); assertSame(beanFactory.getBean(ITestBean.class), injected); }
Example #9
Source File: ConfigurationClassPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void scopedProxyTargetMarkedAsNonAutowireCandidate() { AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(bpp); beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class)); beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class)); ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); pp.postProcessBeanFactory(beanFactory); ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean; assertTrue(injected instanceof ScopedObject); assertSame(beanFactory.getBean("scopedClass"), injected); assertSame(beanFactory.getBean(ITestBean.class), injected); }
Example #10
Source File: TransactionSynchronizationUtils.java From lams with GNU General Public License v2.0 | 5 votes |
public static Object unwrapIfNecessary(Object resource) { if (resource instanceof ScopedObject) { return ((ScopedObject) resource).getTargetObject(); } else { return resource; } }
Example #11
Source File: TransactionSynchronizationUtils.java From java-technology-stack with MIT License | 5 votes |
public static Object unwrapIfNecessary(Object resource) { if (resource instanceof ScopedObject) { return ((ScopedObject) resource).getTargetObject(); } else { return resource; } }
Example #12
Source File: ScopingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testRawScopes() throws Exception { String beanName = "scopedProxyInterface"; // get hidden bean Object bean = ctx.getBean("scopedTarget." + beanName); assertFalse(bean instanceof ScopedObject); }
Example #13
Source File: ConfigurationClassPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void scopedProxyTargetMarkedAsNonAutowireCandidate() { AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(beanFactory); beanFactory.addBeanPostProcessor(bpp); beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ScopedProxyConfigurationClass.class)); beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class)); ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); pp.postProcessBeanFactory(beanFactory); ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean; assertTrue(injected instanceof ScopedObject); assertSame(beanFactory.getBean("scopedClass"), injected); assertSame(beanFactory.getBean(ITestBean.class), injected); }
Example #14
Source File: TransactionSynchronizationUtils.java From spring-analysis-note with MIT License | 5 votes |
public static Object unwrapIfNecessary(Object resource) { if (resource instanceof ScopedObject) { return ((ScopedObject) resource).getTargetObject(); } else { return resource; } }
Example #15
Source File: TransactionSynchronizationUtils.java From spring-analysis-note with MIT License | 5 votes |
public static Object unwrapIfNecessary(Object resource) { if (resource instanceof ScopedObject) { return ((ScopedObject) resource).getTargetObject(); } else { return resource; } }
Example #16
Source File: ScopingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testRawScopes() throws Exception { String beanName = "scopedProxyInterface"; // get hidden bean Object bean = ctx.getBean("scopedTarget." + beanName); assertFalse(bean instanceof ScopedObject); }
Example #17
Source File: GenericScope.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
private boolean isScopedObjectGetTargetObject(Method method) { return method.getDeclaringClass().equals(ScopedObject.class) && method.getName().equals("getTargetObject") && method.getParameterTypes().length == 0; }