本文整理了Java中org.springframework.beans.factory.BeanCreationException.contains()
方法的一些代码示例,展示了BeanCreationException.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanCreationException.contains()
方法的具体详情如下:
包路径:org.springframework.beans.factory.BeanCreationException
类名称:BeanCreationException
方法名:contains
暂无
代码示例来源:origin: spring-projects/spring-framework
if (ex.contains(BeanCurrentlyInCreationException.class)) {
if (logger.isTraceEnabled()) {
logger.trace("Bean currently in creation on FactoryBean type check: " + ex);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testArgNamesError() {
try {
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
fail("Expected BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(IllegalArgumentException.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithInlineScriptWithLeadingWhitespace() throws Exception {
try {
new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass());
fail("Must have thrown a BeanCreationException ('inline:' prefix was preceded by whitespace");
}
catch (BeanCreationException expected) {
assertTrue(expected.contains(FileNotFoundException.class));
}
}
代码示例来源:origin: org.springframework/spring-beans
if (ex.contains(BeanCurrentlyInCreationException.class)) {
if (logger.isTraceEnabled()) {
logger.trace("Bean currently in creation on FactoryBean type check: " + ex);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPrototypeCircleLeadsToException() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
p.setProperty("kerry.(singleton)", "false");
p.setProperty("kerry.age", "35");
p.setProperty("kerry.spouse", "*rod");
p.setProperty("rod.(class)", TestBean.class.getName());
p.setProperty("rod.(singleton)", "false");
p.setProperty("rod.age", "34");
p.setProperty("rod.spouse", "*kerry");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
try {
lbf.getBean("kerry");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextWithInvalidValueType() throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {INVALID_VALUE_TYPE_CONTEXT}, false);
try {
context.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(TypeMismatchException.class));
assertTrue(ex.toString().contains("someMessageSource"));
assertTrue(ex.toString().contains("useCodeAsDefaultMessage"));
checkExceptionFromInvalidValueType(ex);
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
assertFalse(context.isActive());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void circleLeadsToException() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
String name = "requestScopedObjectCircle1";
assertNull(request.getAttribute(name));
this.beanFactory.getBean(name);
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCircularReferencesWithNotAllowed() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
xbf.setAllowCircularReferences(false);
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
try {
xbf.getBean("jenny");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCircularReferencesWithWrapping() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
xbf.addBeanPostProcessor(new WrappingPostProcessor());
try {
xbf.getBean("jenny");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(7, beanCount);
context.refresh();
try {
context.getBean("fooService");
}
catch (BeanCreationException expected) {
assertTrue(expected.contains(BeanInstantiationException.class));
// @Lookup method not substituted
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Mark the specified bean as already created (or about to be created).
* <p>This allows the bean factory to optimize its caching for repeated
* creation of the specified bean.
* @param beanName the name of the bean
*/
protected void markBeanAsCreated(String beanName) {
if (!this.alreadyCreated.contains(beanName)) {
synchronized (this.mergedBeanDefinitions) {
if (!this.alreadyCreated.contains(beanName)) {
// Let the bean definition get re-merged now that we're actually creating
// the bean... just in case some of its metadata changed in the meantime.
clearMergedBeanDefinition(beanName);
this.alreadyCreated.add(beanName);
}
}
}
}
代码示例来源:origin: springframework/spring-beans
public Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
throws BeansException {
String[] beanNames = getBeanNamesForType(type, includePrototypes, includeFactoryBeans);
Map result = CollectionFactory.createLinkedMapIfPossible(beanNames.length);
for (int i = 0; i < beanNames.length; i++) {
String beanName = beanNames[i];
try {
result.put(beanName, getBean(beanName));
}
catch (BeanCreationException ex) {
if (ex.contains(BeanCurrentlyInCreationException.class)) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring match to currently created bean '" + beanName + "'", ex);
}
// Ignore: indicates a circular reference when autowiring constructors.
// We want to find matches other than the currently created bean itself.
}
else {
throw ex;
}
}
}
return result;
}
代码示例来源:origin: springframework/spring-beans
if (ex.contains(BeanCurrentlyInCreationException.class) ||
ex.contains(FactoryBeanNotInitializedException.class)) {
代码示例来源:origin: epam/Wilma
@Test
public void testBootstrapWhenThrowsInvalidPropertyExceptionShouldLogException() {
//GIVEN
given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
given(beanCreationException.getMostSpecificCause()).willReturn(invalidPropertyException);
given(beanCreationException.contains(InvalidPropertyException.class)).willReturn(true);
given(beanCreationException.getCause()).willReturn(invalidPropertyException);
given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(invalidPropertyException);
//WHEN
underTest.bootstrap();
//THEN
verify(systemExceptionSelector).getSystemException(beanCreationException);
verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(), invalidPropertyException);
}
代码示例来源:origin: epam/Wilma
@Test
public void testBootstrapWhenThrowsSchedulingCannotBeStartedExceptionShouldLogException() {
//GIVEN
given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
given(beanCreationException.contains(SchedulingCannotBeStartedException.class)).willReturn(true);
given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException);
given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException);
//WHEN
underTest.bootstrap();
//THEN
verify(systemExceptionSelector).getSystemException(beanCreationException);
verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(),
schedulingCannotBeStartedException);
}
代码示例来源:origin: epam/Wilma
@Test
public void testBootstrapWhenThrowsPropertiesNotAvailableExceptionShouldLogException() {
//GIVEN
given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
given(beanCreationException.contains(PropertiesNotAvailableException.class)).willReturn(true);
given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException);
given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException);
//WHEN
underTest.bootstrap();
//THEN
verify(systemExceptionSelector).getSystemException(beanCreationException);
verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(),
schedulingCannotBeStartedException);
}
代码示例来源:origin: epam/Wilma
@Test
public void testBootstrapShouldLogAnyNonWilmaSpecificException() {
//GIVEN
given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
given(beanCreationException.contains(RuntimeException.class)).willReturn(true);
given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(null);
given(beanCreationException.getCause()).willReturn(null);
//WHEN
underTest.bootstrap();
//THEN
verify(systemExceptionSelector).getSystemException(beanCreationException);
verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG, beanCreationException);
}
}
内容来源于网络,如有侵权,请联系作者删除!