use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithQualifierUnknown.
@Test
public void determineTransactionManagerWithQualifierUnknown() {
BeanFactory beanFactory = mock(BeanFactory.class);
TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setQualifier("fooTransactionManager");
thrown.expect(NoSuchBeanDefinitionException.class);
thrown.expectMessage("'fooTransactionManager'");
ti.determineTransactionManager(attribute);
}
use of org.springframework.beans.factory.BeanFactory in project spring-boot by spring-projects.
the class OnBeanCondition method getMatchingBeans.
private MatchResult getMatchingBeans(ConditionContext context, BeanSearchSpec beans) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
if (beans.getStrategy() == SearchStrategy.ANCESTORS) {
BeanFactory parent = beanFactory.getParentBeanFactory();
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, "Unable to use SearchStrategy.PARENTS");
beanFactory = (ConfigurableListableBeanFactory) parent;
}
MatchResult matchResult = new MatchResult();
boolean considerHierarchy = beans.getStrategy() != SearchStrategy.CURRENT;
List<String> beansIgnoredByType = getNamesOfBeansIgnoredByType(beans.getIgnoredTypes(), beanFactory, context, considerHierarchy);
for (String type : beans.getTypes()) {
Collection<String> typeMatches = getBeanNamesForType(beanFactory, type, context.getClassLoader(), considerHierarchy);
typeMatches.removeAll(beansIgnoredByType);
if (typeMatches.isEmpty()) {
matchResult.recordUnmatchedType(type);
} else {
matchResult.recordMatchedType(type, typeMatches);
}
}
for (String annotation : beans.getAnnotations()) {
List<String> annotationMatches = Arrays.asList(getBeanNamesForAnnotation(beanFactory, annotation, context.getClassLoader(), considerHierarchy));
annotationMatches.removeAll(beansIgnoredByType);
if (annotationMatches.isEmpty()) {
matchResult.recordUnmatchedAnnotation(annotation);
} else {
matchResult.recordMatchedAnnotation(annotation, annotationMatches);
}
}
for (String beanName : beans.getNames()) {
if (!beansIgnoredByType.contains(beanName) && containsBean(beanFactory, beanName, considerHierarchy)) {
matchResult.recordMatchedName(beanName);
} else {
matchResult.recordUnmatchedName(beanName);
}
}
return matchResult;
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class ResourceBundleViewResolver method initFactory.
/**
* Initialize the View {@link BeanFactory} from the {@code ResourceBundle},
* for the given {@link Locale locale}.
* <p>Synchronized because of access by parallel threads.
* @param locale the target {@code Locale}
* @return the View factory for the given Locale
* @throws BeansException in case of initialization errors
*/
protected synchronized BeanFactory initFactory(Locale locale) throws BeansException {
// Have we already encountered that Locale before?
if (isCache()) {
BeanFactory cachedFactory = this.localeCache.get(locale);
if (cachedFactory != null) {
return cachedFactory;
}
}
// Build list of ResourceBundle references for Locale.
List<ResourceBundle> bundles = new LinkedList<>();
for (String basename : this.basenames) {
ResourceBundle bundle = getBundle(basename, locale);
bundles.add(bundle);
}
// even if Locale was different, same bundles might have been found.
if (isCache()) {
BeanFactory cachedFactory = this.bundleCache.get(bundles);
if (cachedFactory != null) {
this.localeCache.put(locale, cachedFactory);
return cachedFactory;
}
}
// Create child ApplicationContext for views.
GenericWebApplicationContext factory = new GenericWebApplicationContext();
factory.setParent(getApplicationContext());
factory.setServletContext(getServletContext());
// Load bean definitions from resource bundle.
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(factory);
reader.setDefaultParentBean(this.defaultParentView);
for (ResourceBundle bundle : bundles) {
reader.registerBeanDefinitions(bundle);
}
factory.refresh();
// Cache factory for both Locale and ResourceBundle list.
if (isCache()) {
this.localeCache.put(locale, factory);
this.bundleCache.put(bundles, factory);
}
return factory;
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class Rollback method testNoProxy.
/**
* If no pointcuts match (no attrs) there should be proxying.
*/
@Test
public void testNoProxy() throws Exception {
BeanFactory bf = getBeanFactory();
Object o = bf.getBean("noSetters");
assertFalse(AopUtils.isAopProxy(o));
}
use of org.springframework.beans.factory.BeanFactory in project spring-framework by spring-projects.
the class Rollback method testTxIsProxied.
@Test
public void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
assertTrue(AopUtils.isAopProxy(test));
}
Aggregations