Java Code Examples for org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator#setProxyTargetClass()

The following examples show how to use org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator#setProxyTargetClass() . 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: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void genericsBasedInjectionWithLateGenericsMatchingOnCglibProxy() {
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
	autoProxyCreator.setProxyTargetClass(true);
	autoProxyCreator.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(autoProxyCreator);
	beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
	beanFactory.preInstantiateSingletons();

	String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
	assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
}
 
Example 2
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void genericsBasedInjectionWithLateGenericsMatchingOnCglibProxyAndRawFactoryMethod() {
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RawFactoryMethodRepositoryConfiguration.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
	autoProxyCreator.setProxyTargetClass(true);
	autoProxyCreator.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(autoProxyCreator);
	beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
	beanFactory.preInstantiateSingletons();

	String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
	assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
}
 
Example 3
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void genericsBasedInjectionWithLateGenericsMatchingOnCglibProxyAndRawInstance() {
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RawInstanceRepositoryConfiguration.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
	autoProxyCreator.setProxyTargetClass(true);
	autoProxyCreator.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(autoProxyCreator);
	beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
	beanFactory.preInstantiateSingletons();

	String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
	assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
}
 
Example 4
Source File: CglibProxyControllerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setProxyTargetClass(true);
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			Pointcut pointcut = new AnnotationMatchingPointcut(Controller.class);
			DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleTraceInterceptor(true));
			wac.getBeanFactory().registerSingleton("advisor", advisor);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());
}
 
Example 5
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void genericsBasedInjectionWithLateGenericsMatchingOnCglibProxyAndRawInstance() {
	beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RawInstanceRepositoryConfiguration.class));
	new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
	DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
	autoProxyCreator.setProxyTargetClass(true);
	autoProxyCreator.setBeanFactory(beanFactory);
	beanFactory.addBeanPostProcessor(autoProxyCreator);
	beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
	beanFactory.preInstantiateSingletons();

	String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
	assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
	assertEquals(1, beanNames.length);
	assertEquals("stringRepo", beanNames[0]);

	assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
}
 
Example 6
Source File: DruidStatConfiguration.java    From druid-spring-boot with Apache License 2.0 5 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator druidStatProxy() {
    log.debug("druid aop-stat init...");
    DefaultAdvisorAutoProxyCreator druidStatProxyCreator = new DefaultAdvisorAutoProxyCreator();
    druidStatProxyCreator.setProxyTargetClass(proxyTargetClass);
    return druidStatProxyCreator;
}
 
Example 7
Source File: ShiroConfig.java    From Goku.Framework.CoreUI with MIT License 5 votes vote down vote up
/**
 * DefaultAdvisorAutoProxyCreator,Spring的一个bean,由Advisor决定对哪些类的方法进行AOP代理。
 */
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
    defaultAAP.setProxyTargetClass(true);
    return defaultAAP;
}
 
Example 8
Source File: ShiroConfig.java    From springboot-shiro with MIT License 5 votes vote down vote up
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
    creator.setProxyTargetClass(true);
    return creator;
}
 
Example 9
Source File: ShiroConfig.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
    defaultAAP.setProxyTargetClass(true);
    return defaultAAP;
}
 
Example 10
Source File: ShiroConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 由Advisor决定对哪些类的方法进行AOP代理。
 * @return
 */
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
    defaultAAP.setProxyTargetClass(true);
    return defaultAAP;
}
 
Example 11
Source File: ShiroConfig.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 开启Shiro的注解(如@RequiresRoles,@RequiresPermissions),需借助SpringAOP扫描使用Shiro注解的类,并在必要时进行安全逻辑验证 * 配置以下两个bean(DefaultAdvisorAutoProxyCreator(可选)和AuthorizationAttributeSourceAdvisor)即可实现此功能
 */
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
    creator.setProxyTargetClass(true);
    return creator;
}
 
Example 12
Source File: ShiroFilterConfiguration.java    From wolf with MIT License 5 votes vote down vote up
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator getAutoProxyCreator(){
    DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
    creator.setProxyTargetClass(true);
    return creator;
}
 
Example 13
Source File: ShiroConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 由Advisor决定对哪些类的方法进行AOP代理。
 * @return
 */
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
    defaultAAP.setProxyTargetClass(true);
    return defaultAAP;
}
 
Example 14
Source File: ShiroConfig.java    From dts-shop with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public static DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
	DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
	creator.setProxyTargetClass(true);
	return creator;
}
 
Example 15
Source File: AbstractIamConfiguration.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Bean
@DependsOn("lifecycleBeanPostProcessor")
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
	DefaultAdvisorAutoProxyCreator advisorCreator = new DefaultAdvisorAutoProxyCreator();
	advisorCreator.setProxyTargetClass(true);
	return advisorCreator;
}
 
Example 16
Source File: WebMvcAppContext.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
    proxyCreator.setProxyTargetClass(true);
    return proxyCreator;
}
 
Example 17
Source File: ShiroConfig.java    From EasyReport with Apache License 2.0 4 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    final DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
    daap.setProxyTargetClass(true);
    return daap;
}
 
Example 18
Source File: ShiroConfiguration.java    From jee-universal-bms with Apache License 2.0 4 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
    daap.setProxyTargetClass(true);
    return daap;
}
 
Example 19
Source File: ShiroConfig.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
	DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
	creator.setProxyTargetClass(true);
	return creator;
}
 
Example 20
Source File: ShiroConfig.java    From springboot-admin with Apache License 2.0 4 votes vote down vote up
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator proxyCreator = new DefaultAdvisorAutoProxyCreator();
    proxyCreator.setProxyTargetClass(true);
    return proxyCreator;
}