org.springframework.beans.factory.BeanCreationException.contains()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中org.springframework.beans.factory.BeanCreationException.contains()方法的一些代码示例,展示了BeanCreationException.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanCreationException.contains()方法的具体详情如下:
包路径:org.springframework.beans.factory.BeanCreationException
类名称:BeanCreationException
方法名:contains

BeanCreationException.contains介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. if (ex.contains(BeanCurrentlyInCreationException.class)) {
  2. if (logger.isTraceEnabled()) {
  3. logger.trace("Bean currently in creation on FactoryBean type check: " + ex);

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testArgNamesError() {
  3. try {
  4. new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
  5. fail("Expected BeanCreationException");
  6. }
  7. catch (BeanCreationException ex) {
  8. assertTrue(ex.contains(IllegalArgumentException.class));
  9. }
  10. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testWithInlineScriptWithLeadingWhitespace() throws Exception {
  3. try {
  4. new ClassPathXmlApplicationContext("lwspBadGroovyContext.xml", getClass());
  5. fail("Must have thrown a BeanCreationException ('inline:' prefix was preceded by whitespace");
  6. }
  7. catch (BeanCreationException expected) {
  8. assertTrue(expected.contains(FileNotFoundException.class));
  9. }
  10. }

代码示例来源:origin: org.springframework/spring-beans

  1. if (ex.contains(BeanCurrentlyInCreationException.class)) {
  2. if (logger.isTraceEnabled()) {
  3. logger.trace("Bean currently in creation on FactoryBean type check: " + ex);

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testPrototypeCircleLeadsToException() {
  3. DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
  4. Properties p = new Properties();
  5. p.setProperty("kerry.(class)", TestBean.class.getName());
  6. p.setProperty("kerry.(singleton)", "false");
  7. p.setProperty("kerry.age", "35");
  8. p.setProperty("kerry.spouse", "*rod");
  9. p.setProperty("rod.(class)", TestBean.class.getName());
  10. p.setProperty("rod.(singleton)", "false");
  11. p.setProperty("rod.age", "34");
  12. p.setProperty("rod.spouse", "*kerry");
  13. (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
  14. try {
  15. lbf.getBean("kerry");
  16. fail("Should have thrown BeanCreationException");
  17. }
  18. catch (BeanCreationException ex) {
  19. // expected
  20. assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
  21. }
  22. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testContextWithInvalidValueType() throws IOException {
  3. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
  4. new String[] {INVALID_VALUE_TYPE_CONTEXT}, false);
  5. try {
  6. context.refresh();
  7. fail("Should have thrown BeanCreationException");
  8. }
  9. catch (BeanCreationException ex) {
  10. assertTrue(ex.contains(TypeMismatchException.class));
  11. assertTrue(ex.toString().contains("someMessageSource"));
  12. assertTrue(ex.toString().contains("useCodeAsDefaultMessage"));
  13. checkExceptionFromInvalidValueType(ex);
  14. checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
  15. assertFalse(context.isActive());
  16. }
  17. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void circleLeadsToException() throws Exception {
  3. MockHttpServletRequest request = new MockHttpServletRequest();
  4. RequestAttributes requestAttributes = new ServletRequestAttributes(request);
  5. RequestContextHolder.setRequestAttributes(requestAttributes);
  6. try {
  7. String name = "requestScopedObjectCircle1";
  8. assertNull(request.getAttribute(name));
  9. this.beanFactory.getBean(name);
  10. fail("Should have thrown BeanCreationException");
  11. }
  12. catch (BeanCreationException ex) {
  13. assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
  14. }
  15. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testCircularReferencesWithNotAllowed() {
  3. DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  4. xbf.setAllowCircularReferences(false);
  5. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
  6. reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
  7. reader.loadBeanDefinitions(REFTYPES_CONTEXT);
  8. try {
  9. xbf.getBean("jenny");
  10. fail("Should have thrown BeanCreationException");
  11. }
  12. catch (BeanCreationException ex) {
  13. assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
  14. }
  15. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testCircularReferencesWithWrapping() {
  3. DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  4. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
  5. reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
  6. reader.loadBeanDefinitions(REFTYPES_CONTEXT);
  7. xbf.addBeanPostProcessor(new WrappingPostProcessor());
  8. try {
  9. xbf.getBean("jenny");
  10. fail("Should have thrown BeanCreationException");
  11. }
  12. catch (BeanCreationException ex) {
  13. assertTrue(ex.contains(BeanCurrentlyInCreationException.class));
  14. }
  15. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
  3. GenericApplicationContext context = new GenericApplicationContext();
  4. ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
  5. scanner.setIncludeAnnotationConfig(false);
  6. scanner.setBeanNameGenerator(new TestBeanNameGenerator());
  7. int beanCount = scanner.scan(BASE_PACKAGE);
  8. assertEquals(7, beanCount);
  9. context.refresh();
  10. try {
  11. context.getBean("fooService");
  12. }
  13. catch (BeanCreationException expected) {
  14. assertTrue(expected.contains(BeanInstantiationException.class));
  15. // @Lookup method not substituted
  16. }
  17. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Mark the specified bean as already created (or about to be created).
  3. * <p>This allows the bean factory to optimize its caching for repeated
  4. * creation of the specified bean.
  5. * @param beanName the name of the bean
  6. */
  7. protected void markBeanAsCreated(String beanName) {
  8. if (!this.alreadyCreated.contains(beanName)) {
  9. synchronized (this.mergedBeanDefinitions) {
  10. if (!this.alreadyCreated.contains(beanName)) {
  11. // Let the bean definition get re-merged now that we're actually creating
  12. // the bean... just in case some of its metadata changed in the meantime.
  13. clearMergedBeanDefinition(beanName);
  14. this.alreadyCreated.add(beanName);
  15. }
  16. }
  17. }
  18. }

代码示例来源:origin: springframework/spring-beans

  1. public Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
  2. throws BeansException {
  3. String[] beanNames = getBeanNamesForType(type, includePrototypes, includeFactoryBeans);
  4. Map result = CollectionFactory.createLinkedMapIfPossible(beanNames.length);
  5. for (int i = 0; i < beanNames.length; i++) {
  6. String beanName = beanNames[i];
  7. try {
  8. result.put(beanName, getBean(beanName));
  9. }
  10. catch (BeanCreationException ex) {
  11. if (ex.contains(BeanCurrentlyInCreationException.class)) {
  12. if (logger.isDebugEnabled()) {
  13. logger.debug("Ignoring match to currently created bean '" + beanName + "'", ex);
  14. }
  15. // Ignore: indicates a circular reference when autowiring constructors.
  16. // We want to find matches other than the currently created bean itself.
  17. }
  18. else {
  19. throw ex;
  20. }
  21. }
  22. }
  23. return result;
  24. }

代码示例来源:origin: springframework/spring-beans

  1. if (ex.contains(BeanCurrentlyInCreationException.class) ||
  2. ex.contains(FactoryBeanNotInitializedException.class)) {

代码示例来源:origin: epam/Wilma

  1. @Test
  2. public void testBootstrapWhenThrowsInvalidPropertyExceptionShouldLogException() {
  3. //GIVEN
  4. given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
  5. given(beanCreationException.getMostSpecificCause()).willReturn(invalidPropertyException);
  6. given(beanCreationException.contains(InvalidPropertyException.class)).willReturn(true);
  7. given(beanCreationException.getCause()).willReturn(invalidPropertyException);
  8. given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(invalidPropertyException);
  9. //WHEN
  10. underTest.bootstrap();
  11. //THEN
  12. verify(systemExceptionSelector).getSystemException(beanCreationException);
  13. verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(), invalidPropertyException);
  14. }

代码示例来源:origin: epam/Wilma

  1. @Test
  2. public void testBootstrapWhenThrowsSchedulingCannotBeStartedExceptionShouldLogException() {
  3. //GIVEN
  4. given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
  5. given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
  6. given(beanCreationException.contains(SchedulingCannotBeStartedException.class)).willReturn(true);
  7. given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException);
  8. given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException);
  9. //WHEN
  10. underTest.bootstrap();
  11. //THEN
  12. verify(systemExceptionSelector).getSystemException(beanCreationException);
  13. verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(),
  14. schedulingCannotBeStartedException);
  15. }

代码示例来源:origin: epam/Wilma

  1. @Test
  2. public void testBootstrapWhenThrowsPropertiesNotAvailableExceptionShouldLogException() {
  3. //GIVEN
  4. given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
  5. given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
  6. given(beanCreationException.contains(PropertiesNotAvailableException.class)).willReturn(true);
  7. given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException);
  8. given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException);
  9. //WHEN
  10. underTest.bootstrap();
  11. //THEN
  12. verify(systemExceptionSelector).getSystemException(beanCreationException);
  13. verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(),
  14. schedulingCannotBeStartedException);
  15. }

代码示例来源:origin: epam/Wilma

  1. @Test
  2. public void testBootstrapShouldLogAnyNonWilmaSpecificException() {
  3. //GIVEN
  4. given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException);
  5. given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException);
  6. given(beanCreationException.contains(RuntimeException.class)).willReturn(true);
  7. given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(null);
  8. given(beanCreationException.getCause()).willReturn(null);
  9. //WHEN
  10. underTest.bootstrap();
  11. //THEN
  12. verify(systemExceptionSelector).getSystemException(beanCreationException);
  13. verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG, beanCreationException);
  14. }
  15. }

相关文章