Top Description Fields Constructors Methods
org.springframework.aop.framework.autoproxy

public Class BeanNameAutoProxyCreator

extends AbstractAutoProxyCreator
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.util.ArrayList, .List, org.springframework.aop.TargetSource, org.springframework.beans.factory.BeanFactory, .FactoryBean, org.springframework.lang.Nullable, org.springframework.util.Assert, .PatternMatchUtils

Auto proxy creator that identifies beans to proxy via a list of names. Checks for direct, "xxx*", and "*xxx" matches.

For configuration details, see the javadoc of the parent class AbstractAutoProxyCreator. Typically, you will specify a list of interceptor names to apply to all identified beans, via the "interceptorNames" property.

Authors
Juergen Hoeller, Sam Brannen
Since
10.10.2003
See Also
setBeanNames, isMatch, setInterceptorNames, AbstractAutoProxyCreator

Field Summary

Modifier and TypeField and Description
private List<String>
private static final String[]
Inherited from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator:
DO_NOT_PROXYloggerPROXY_WITHOUT_ADDITIONAL_INTERCEPTORS

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Object[]
getAdvicesAndAdvisorsForBean(Class<?>
the class of the bean to advise
beanClass
,
String
the name of the bean
beanName
,
TargetSource
the TargetSource returned by the getCustomTargetSource method: may be ignored. Will be null if no custom target source is in use.
targetSource
)

Implements abstract org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

Identify as a bean to proxy if the bean name matches one of the names in the configured list of supported names.
protected TargetSource
getCustomTargetSource(Class<?>
the class of the bean to create a TargetSource for
beanClass
,
String
the name of the bean
beanName
)

Overrides org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getCustomTargetSource.

Delegate to AbstractAutoProxyCreator#getCustomTargetSource(Class, String) if the bean name matches one of the names in the configured list of supported names, returning null otherwise.
protected boolean

Returns:

if the names match
isMatch
(String
the bean name to check
beanName
,
String
the name in the configured list of names
mappedName
)

Determine if the given bean name matches the mapped name.

private boolean

Returns:

true if the given bean name is supported
isSupportedBeanName
(Class<?>
the class of the bean to advise
beanClass
,
String
the name of the bean
beanName
)

Determine if the bean name for the given bean class matches one of the names in the configured list of supported names.

public void
setBeanNames(String... beanNames)

Set the names of the beans that should automatically get wrapped with proxies.

Inherited from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator:
advisorsPreFilteredbuildAdvisorscreateProxycustomizeProxyFactorydetermineBeanTypedetermineCandidateConstructorsgetBeanFactorygetCacheKeygetEarlyBeanReferenceisFrozenisInfrastructureClasspostProcessAfterInitializationpostProcessBeforeInstantiationpostProcessPropertiespredictBeanTypesetAdvisorAdapterRegistrysetApplyCommonInterceptorsFirstsetBeanFactorysetCustomTargetSourceCreatorssetFrozensetInterceptorNamesshouldProxyTargetClassshouldSkipwrapIfNecessary

Field Detail

beanNamesback to summary
private List<String> beanNames
Annotations
@Nullable
NO_ALIASESback to summary
private static final String[] NO_ALIASES

Constructor Detail

BeanNameAutoProxyCreatorback to summary
public BeanNameAutoProxyCreator()

Method Detail

getAdvicesAndAdvisorsForBeanback to summary
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource targetSource)

Implements abstract org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

Identify as a bean to proxy if the bean name matches one of the names in the configured list of supported names.

Parameters
beanClass:Class<?>

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

the class of the bean to advise

beanName:String

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

the name of the bean

targetSource:TargetSource

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

the TargetSource returned by the getCustomTargetSource method: may be ignored. Will be null if no custom target source is in use.

Returns:Object[]

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean.

an array of additional interceptors for the particular bean; or an empty array if no additional interceptors but just the common ones; or null if no proxy at all, not even with the common interceptors. See constants DO_NOT_PROXY and PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS.

Annotations
@Override
@Nullable
See Also
setBeanNames(String...)
getCustomTargetSourceback to summary
protected TargetSource getCustomTargetSource(Class<?> beanClass, String beanName)

Overrides org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getCustomTargetSource.

Delegate to AbstractAutoProxyCreator#getCustomTargetSource(Class, String) if the bean name matches one of the names in the configured list of supported names, returning null otherwise.

Parameters
beanClass:Class<?>

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getCustomTargetSource.

the class of the bean to create a TargetSource for

beanName:String

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getCustomTargetSource.

the name of the bean

Returns:TargetSource

Doc from org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getCustomTargetSource.

a TargetSource for this bean

Annotations
@Override
Since
5.3
See Also
setBeanNames(String...)
isMatchback to summary
protected boolean isMatch(String beanName, String mappedName)

Determine if the given bean name matches the mapped name.

The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality. Can be overridden in subclasses.

Parameters
beanName:String

the bean name to check

mappedName:String

the name in the configured list of names

Returns:boolean

if the names match

See Also
org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
isSupportedBeanNameback to summary
private boolean isSupportedBeanName(Class<?> beanClass, String beanName)

Determine if the bean name for the given bean class matches one of the names in the configured list of supported names.

Parameters
beanClass:Class<?>

the class of the bean to advise

beanName:String

the name of the bean

Returns:boolean

true if the given bean name is supported

See Also
setBeanNames(String...)
setBeanNamesback to summary
public void setBeanNames(String... beanNames)

Set the names of the beans that should automatically get wrapped with proxies. A name can specify a prefix to match by ending with "*", e.g. "myBean,tx*" will match the bean named "myBean" and all beans whose name start with "tx".

Note

In case of a FactoryBean, only the objects created by the FactoryBean will get proxied. This default behavior applies as of Spring 2.0. If you intend to proxy a FactoryBean instance itself (a rare use case, but Spring 1.2's default behavior), specify the bean name of the FactoryBean including the factory-bean prefix "&": e.g. "&myFactoryBean".

See Also
org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.BeanFactory#FACTORY_BEAN_PREFIX