@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
java类org.springframework.context.annotation.ScopedProxyMode的实例源码
OAuth2RestOperationsConfiguration.java 文件源码
项目:spring-security-oauth2-boot
阅读 46
收藏 0
点赞 0
评论 0
FacebookConfiguration.java 文件源码
项目:OAuth-2.0-Cookbook
阅读 36
收藏 0
点赞 0
评论 0
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository
.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
CdiScopeMetadataResolver.java 文件源码
项目:app-ms
阅读 55
收藏 0
点赞 0
评论 0
@Override
public ScopeMetadata resolveScopeMetadata(final BeanDefinition definition) {
if (definition instanceof AnnotatedBeanDefinition) {
final AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) definition;
final ScopeMetadata metadata = new ScopeMetadata();
final Set<String> annotationTypes = beanDefinition.getMetadata().getAnnotationTypes();
if (annotationTypes.contains(RequestScoped.class
.getName())) {
metadata.setScopeName("request");
metadata.setScopedProxyMode(ScopedProxyMode.TARGET_CLASS);
} else if (annotationTypes
.contains(ApplicationScoped.class.getName())) {
metadata.setScopeName("singleton");
} else {
return super.resolveScopeMetadata(definition);
}
return metadata;
} else {
return super.resolveScopeMetadata(definition);
}
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 47
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
assertTrue(context.isSingleton("singleton"));
assertFalse(context.isPrototype("singleton"));
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 38
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 48
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("request");
assertEquals(DEFAULT_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 41
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
// should be dynamic proxy, implementing both interfaces
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertTrue(bean instanceof AnotherScopeTestInterface);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 43
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
assertTrue(bean instanceof RequestScopedTestBean);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 33
收藏 0
点赞 0
评论 0
@Test
public void testSessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("session");
assertEquals(DEFAULT_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 47
收藏 0
点赞 0
评论 0
@Test
public void testSessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
// should be dynamic proxy, implementing both interfaces
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertTrue(bean instanceof AnotherScopeTestInterface);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
IScopedTestBean bean2 = (IScopedTestBean) context.getBean("session");
assertEquals(MODIFIED_NAME, bean2.getName());
bean2.setName(DEFAULT_NAME);
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 46
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 39
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("request");
assertEquals(DEFAULT_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 38
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
// should be dynamic proxy, implementing both interfaces
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertTrue(bean instanceof AnotherScopeTestInterface);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
assertTrue(bean instanceof RequestScopedTestBean);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 46
收藏 0
点赞 0
评论 0
@Test
public void testSessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("session");
assertEquals(DEFAULT_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void testSessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
// should be dynamic proxy, implementing both interfaces
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertTrue(bean instanceof AnotherScopeTestInterface);
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributesWithSession);
// this is a proxy so it should be reset to default
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
IScopedTestBean bean2 = (IScopedTestBean) context.getBean("session");
assertEquals(MODIFIED_NAME, bean2.getName());
bean2.setName(DEFAULT_NAME);
assertEquals(DEFAULT_NAME, bean.getName());
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
assertEquals(MODIFIED_NAME, bean.getName());
}
ClassPathBeanDefinitionScannerScopeIntegrationTests.java 文件源码
项目:spring4-understanding
阅读 38
收藏 0
点赞 0
评论 0
private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) {
GenericWebApplicationContext context = new GenericWebApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new BeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return definition.getScope();
}
});
scanner.setScopedProxyMode(scopedProxyMode);
// Scan twice in order to find errors in the bean definition compatibility check.
scanner.scan(getClass().getPackage().getName());
scanner.scan(getClass().getPackage().getName());
context.refresh();
return context;
}
OAuth2RestOperationsConfiguration.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 49
收藏 0
点赞 0
评论 0
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
FacebookAutoConfiguration.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 41
收藏 0
点赞 0
评论 0
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository
.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
OAuth2RestOperationsConfiguration.java 文件源码
项目:spring-boot-concourse
阅读 32
收藏 0
点赞 0
评论 0
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
FacebookAutoConfiguration.java 文件源码
项目:spring-boot-concourse
阅读 28
收藏 0
点赞 0
评论 0
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository
.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
OAuth2RestOperationsConfiguration.java 文件源码
项目:contestparser
阅读 49
收藏 0
点赞 0
评论 0
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
AppConfig.java 文件源码
项目:metl
阅读 43
收藏 0
点赞 0
评论 0
@Bean
@Scope(value = "singleton", proxyMode = ScopedProxyMode.INTERFACES)
Service brokerService() {
if (brokerService == null) {
try {
BrokerService broker = new BrokerService();
broker.setPersistent(false);
broker.getSystemUsage().getMemoryUsage().setLimit(10*1024*10);
broker.start();
brokerService = broker;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return brokerService;
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:class-guard
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
assertTrue(context.isSingleton("singleton"));
assertFalse(context.isPrototype("singleton"));
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:class-guard
阅读 31
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:class-guard
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void testSingletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// singleton bean, so name should be modified even after lookup
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
assertEquals(MODIFIED_NAME, bean2.getName());
}
ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java 文件源码
项目:class-guard
阅读 38
收藏 0
点赞 0
评论 0
@Test
public void testRequestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertEquals(DEFAULT_NAME, bean.getName());
bean.setName(MODIFIED_NAME);
RequestContextHolder.setRequestAttributes(newRequestAttributes);
// not a proxy so this should not have changed
assertEquals(MODIFIED_NAME, bean.getName());
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("request");
assertEquals(DEFAULT_NAME, bean2.getName());
}