Class DependencyInjectionAspectSupport
- java.lang.Object
-
- org.springframework.orm.hibernate.support.DependencyInjectionAspectSupport
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
DependencyInjectionInterceptorFactoryBean
public abstract class DependencyInjectionAspectSupport extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware
Convenient superclass for aspects/persistence API configuration classes that should be able to autowire objects into a factory.There are two ways of doing this: by mapping managed classes to prototype bean definitions in the factory; and by identifying classes of which instances should be autowired into the factory using the autowiring capables of AutowireCapableBeanFactory. If your managed class implements Spring lifecycle interfaces such as BeanFactoryAware or ApplicationContextAware, you must use the former method. With the latter method, only properties will be set, based on automatic satisfaction of dependencies from other beans (singleton or non-singleton) defined in the factory.
Could also use attributes on persistent classes to identify those eligible for autowiring, or even the prototype bean name.
- Since:
- 1.2
- Author:
- Rod Johnson
- See Also:
AutowireCapableBeanFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
-
Field Summary
Fields Modifier and Type Field Description protected List
autowireByTypeClasses
List of Classprotected org.apache.log4j.Logger
log
-
Constructor Summary
Constructors Constructor Description DependencyInjectionAspectSupport()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addAutowireByNameClass(Class clazz)
void
addAutowireByTypeClass(Class clazz)
void
addManagedClassToPrototypeMapping(Class clazz, String beanName)
void
afterPropertiesSet()
Check that mandatory properties were setprotected void
autowireProperties(Object o)
Subclasses can call this to autowire properties on an existing objectprotected Object
createAndConfigure(Class clazz)
Subclasses will call this to create an object of the requisite classList
getAutowireByNameClasses()
Return classes autowired by nameList
getAutowireByTypeClasses()
Return classes autowired by typeprotected org.springframework.beans.factory.BeanFactory
getBeanFactory()
Expose the owning bean factory to subclasses.int
getDefaultAutowireMode()
Map
getManagedClassToPrototypeNames()
Return a Map of managed classes to prototype namesvoid
setAutowireByNameClasses(List autowireByNameClasses)
Set the Classes or class names that will be autowired by namevoid
setAutowireByTypeClasses(List autowireByTypeClasses)
Set the Classes or class names that will be autowired by typevoid
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
void
setDefaultAutowireMode(int mode)
Convenient property enabling autowiring of all instances.void
setManagedClassNamesToPrototypeNames(Properties persistentClassBeanNames)
Property key is class FQN, value is prototype name to use to obtain a new instanceprotected void
validateConfiguration()
protected abstract void
validateProperties()
Subclasses should implement this to validate their configuration
-
-
-
Field Detail
-
log
protected final org.apache.log4j.Logger log
-
autowireByTypeClasses
protected List autowireByTypeClasses
List of Class
-
-
Method Detail
-
getDefaultAutowireMode
public int getDefaultAutowireMode()
- Returns:
- Returns the autowireAll.
-
setDefaultAutowireMode
public void setDefaultAutowireMode(int mode)
Convenient property enabling autowiring of all instances. We might want this in an AspectJ aspect subclass, for example, relying on the AspectJ aspect to target the advice.- Parameters:
mode
- The autowireAll to set.
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
- Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
-
getBeanFactory
protected org.springframework.beans.factory.BeanFactory getBeanFactory()
Expose the owning bean factory to subclasses. Call only after initialization is complete.- Returns:
- the owning bean factory. Cannot be null in valid use of this class.
-
setAutowireByTypeClasses
public void setAutowireByTypeClasses(List autowireByTypeClasses)
Set the Classes or class names that will be autowired by type- Parameters:
autowireByTypeClasses
- list of Class or String classname
-
getAutowireByTypeClasses
public List getAutowireByTypeClasses()
Return classes autowired by type- Returns:
- list of Class
-
addAutowireByTypeClass
public void addAutowireByTypeClass(Class clazz)
-
setAutowireByNameClasses
public void setAutowireByNameClasses(List autowireByNameClasses)
Set the Classes or class names that will be autowired by name- Parameters:
autowireByNameClasses
- list of Class or String classname
-
getAutowireByNameClasses
public List getAutowireByNameClasses()
Return classes autowired by name- Returns:
- list of Class
-
addAutowireByNameClass
public void addAutowireByNameClass(Class clazz)
-
setManagedClassNamesToPrototypeNames
public void setManagedClassNamesToPrototypeNames(Properties persistentClassBeanNames)
Property key is class FQN, value is prototype name to use to obtain a new instance- Parameters:
persistentClassBeanNames
-
-
getManagedClassToPrototypeNames
public Map getManagedClassToPrototypeNames()
Return a Map of managed classes to prototype names- Returns:
- Map with key being FQN and value prototype bean name to use for that class
-
addManagedClassToPrototypeMapping
public void addManagedClassToPrototypeMapping(Class clazz, String beanName)
-
afterPropertiesSet
public final void afterPropertiesSet()
Check that mandatory properties were set- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- See Also:
InitializingBean.afterPropertiesSet()
-
validateProperties
protected abstract void validateProperties()
Subclasses should implement this to validate their configuration
-
validateConfiguration
protected void validateConfiguration()
-
autowireProperties
protected void autowireProperties(Object o) throws DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException, org.springframework.beans.BeansException
Subclasses can call this to autowire properties on an existing object- Parameters:
o
-- Throws:
org.springframework.beans.BeansException
DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
-
createAndConfigure
protected Object createAndConfigure(Class clazz) throws DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
Subclasses will call this to create an object of the requisite class- Parameters:
clazz
-- Returns:
- Throws:
DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
-
-