|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.powertac.common.spring.SpringApplicationContext
@Service public class SpringApplicationContext
Static methods to access the Spring application context. It is set up as a service so Spring will create and initialize it. NOTE: These methods should NOT be used in constructors. Doing so makes it vitually impossible to test with mocks, and makes transitive dependencies very difficult in a test environment. Better to use them in individual "service getter" methods that do nothing for dependencies that have already been satisfied by test code using ReflectionTestUtils.setField(). ALSO NOTE: Even when used outside a constructor, there are still potential problems in a test environment, because if any test in a suite initializes Spring, then later tests that do not initialize Spring can retrieve instances from earlier tests, which may not be what the test expects. This can lead to baffling problems.
| Constructor Summary | |
|---|---|
SpringApplicationContext()
|
|
| Method Summary | ||
|---|---|---|
static Object |
getBean(String beanName)
Returns the Spring bean, if any, with the given name. |
|
static
|
getBeanByType(Class<T> type)
Returns the first Spring bean found that is an instance of the given class. |
|
static org.springframework.context.ApplicationContext |
getContext()
|
|
static
|
listBeansOfType(Class<T> type)
Returns all the Spring beans that are instances of the given type. |
|
static
|
mapBeansOfType(Class<T> type)
Returns a map of all the Spring beans that are instances of the given type. |
|
void |
setApplicationContext(org.springframework.context.ApplicationContext appContext)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SpringApplicationContext()
| Method Detail |
|---|
public void setApplicationContext(org.springframework.context.ApplicationContext appContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic static Object getBean(String beanName)
public static <T> T getBeanByType(Class<T> type)
public static <T> List<T> listBeansOfType(Class<T> type)
public static <T> Map<String,T> mapBeansOfType(Class<T> type)
public static org.springframework.context.ApplicationContext getContext()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||