List of usage examples for org.springframework.context.annotation ScopedProxyMode TARGET_CLASS
ScopedProxyMode TARGET_CLASS
To view the source code for org.springframework.context.annotation ScopedProxyMode TARGET_CLASS.
Click Source Link
From source file:org.owasp.webgoat.WebGoat.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public WebSession webSession(WebgoatContext webgoatContext) { return new WebSession(webgoatContext); }
From source file:org.owasp.webgoat.WebGoat.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public UserSessionData userSessionData() { return new UserSessionData("test", "data"); }
From source file:org.homiefund.config.ApplicationConfiguration.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) @Description("Holder bean containing \"Cached\" values for various parts of application.") public UserPreferencesBean pageModel() { return new UserPreferencesBean(); }
From source file:org.owasp.webgoat.WebGoat.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) @SneakyThrows//from w ww . j a v a 2 s. com public UserTracker userTracker(@Value("${webgoat.user.directory}") final String webgoatHome, WebSession webSession) { UserTracker userTracker = new UserTracker(webgoatHome, webSession.getUserName()); userTracker.load(); return userTracker; }
From source file:br.com.caelum.vraptor.ioc.spring.SpringRegistry.java
/** * From org.springframework.context.annotation.ClassPathBeanDefinitionScanner#applyScope() * @param definition/* w ww . ja v a2 s . c om*/ * @param scopeMetadata * * @return */ private BeanDefinitionHolder applyScopeOn(BeanDefinitionHolder definition, ScopeMetadata scopeMetadata) { String scope = scopeMetadata.getScopeName(); ScopedProxyMode proxyMode = scopeMetadata.getScopedProxyMode(); definition.getBeanDefinition().setScope(scope); if (BeanDefinition.SCOPE_SINGLETON.equals(scope) || BeanDefinition.SCOPE_PROTOTYPE.equals(scope) || proxyMode.equals(ScopedProxyMode.NO)) { return definition; } else { boolean proxyTargetClass = proxyMode.equals(ScopedProxyMode.TARGET_CLASS); return ScopedProxyUtils.createScopedProxy(definition, (BeanDefinitionRegistry) beanFactory, proxyTargetClass); } }
From source file:org.rosenvold.spring.convention.ConventionBeanFactory.java
private void registerBeanByResolvedType(String beanName, Class<?> resolvedType) { if (resolvedType == null) return;//ww w. ja v a 2 s.c o m final BeanDefinition beanDefinition = getOrCreateBeanDefinition(beanName, resolvedType); BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(beanDefinition, beanName); ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(beanDefinition); ScopedProxyMode scopedProxyMode = scopeMetadata.getScopedProxyMode(); if (!scopedProxyMode.equals(ScopedProxyMode.NO)) { definitionHolder = ScopedProxyUtils.createScopedProxy(definitionHolder, this, scopedProxyMode.equals(ScopedProxyMode.TARGET_CLASS)); } registerBeanDefinition(beanName, definitionHolder.getBeanDefinition()); }
From source file:org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.java
/** * Read the given {@link BeanMethod}, registering bean definitions * with the BeanDefinitionRegistry based on its contents. *//*from w ww.j a v a 2 s . c o m*/ private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) { ConfigurationClass configClass = beanMethod.getConfigurationClass(); MethodMetadata metadata = beanMethod.getMetadata(); String methodName = metadata.getMethodName(); // Do we need to mark the bean as skipped by its condition? if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) { configClass.skippedBeanMethods.add(methodName); return; } if (configClass.skippedBeanMethods.contains(methodName)) { return; } AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.class); Assert.state(bean != null, "No @Bean annotation attributes"); // Consider name and any aliases List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name"))); String beanName = (!names.isEmpty() ? names.remove(0) : methodName); // Register aliases even when overridden for (String alias : names) { this.registry.registerAlias(beanName, alias); } // Has this effectively been overridden before (e.g. via XML)? if (isOverriddenByExistingDefinition(beanMethod, beanName)) { if (beanName.equals(beanMethod.getConfigurationClass().getBeanName())) { throw new BeanDefinitionStoreException( beanMethod.getConfigurationClass().getResource().getDescription(), beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() + "' clashes with bean name for containing configuration class; please make those names unique!"); } return; } ConfigurationClassBeanDefinition beanDef = new ConfigurationClassBeanDefinition(configClass, metadata); beanDef.setResource(configClass.getResource()); beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClass.getResource())); if (metadata.isStatic()) { // static @Bean method beanDef.setBeanClassName(configClass.getMetadata().getClassName()); beanDef.setFactoryMethodName(methodName); } else { // instance @Bean method beanDef.setFactoryBeanName(configClass.getBeanName()); beanDef.setUniqueFactoryMethodName(methodName); } beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE); AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata); Autowire autowire = bean.getEnum("autowire"); if (autowire.isAutowire()) { beanDef.setAutowireMode(autowire.value()); } String initMethodName = bean.getString("initMethod"); if (StringUtils.hasText(initMethodName)) { beanDef.setInitMethodName(initMethodName); } String destroyMethodName = bean.getString("destroyMethod"); beanDef.setDestroyMethodName(destroyMethodName); // Consider scoping ScopedProxyMode proxyMode = ScopedProxyMode.NO; AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.class); if (attributes != null) { beanDef.setScope(attributes.getString("value")); proxyMode = attributes.getEnum("proxyMode"); if (proxyMode == ScopedProxyMode.DEFAULT) { proxyMode = ScopedProxyMode.NO; } } // Replace the original bean definition with the target one, if necessary BeanDefinition beanDefToRegister = beanDef; if (proxyMode != ScopedProxyMode.NO) { BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy( new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS); beanDefToRegister = new ConfigurationClassBeanDefinition( (RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata); } if (logger.isDebugEnabled()) { logger.debug(String.format("Registering bean definition for @Bean method %s.%s()", configClass.getMetadata().getClassName(), beanName)); } this.registry.registerBeanDefinition(beanName, beanDefToRegister); }