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

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

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

BeanCreationException.getMostSpecificCause介绍

暂无

代码示例

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
  2. if (logger.isTraceEnabled()) {
  3. logger.trace("Could not determine scripted object type for bean '" + beanName + "': " +

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

  1. ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
  2. if (logger.isTraceEnabled()) {
  3. logger.trace("Could not determine scripted object type for bean '" + beanName + "': " +

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. @Test
  2. public void testConstructor() throws Exception {
  3. try {
  4. beanFactory.getBean("constructor");
  5. fail("expected security exception");
  6. }
  7. catch (BeanCreationException ex) {
  8. // expected
  9. assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
  10. }
  11. }

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

  1. @Test
  2. public void testTrustedFactoryMethod() throws Exception {
  3. try {
  4. beanFactory.getBean("privileged-static-factory-method");
  5. fail("expected security exception");
  6. }
  7. catch (BeanCreationException ex) {
  8. assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
  9. }
  10. }

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

  1. @Test
  2. public void testCustomStaticFactoryMethod() throws Exception {
  3. try {
  4. beanFactory.getBean("custom-static-factory-method");
  5. fail("expected security exception");
  6. }
  7. catch (BeanCreationException ex) {
  8. assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
  9. }
  10. }

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

  1. @Test
  2. public void testCustomInstanceFactoryMethod() throws Exception {
  3. try {
  4. beanFactory.getBean("custom-factory-method");
  5. fail("expected security exception");
  6. }
  7. catch (BeanCreationException ex) {
  8. assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
  9. }
  10. }

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

  1. Throwable rootCause = ex.getMostSpecificCause();
  2. if (rootCause instanceof BeanCurrentlyInCreationException) {
  3. BeanCreationException bce = (BeanCreationException) rootCause;

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

  1. @Test
  2. public void testNonLenientDependencyMatchingFactoryMethod() {
  3. DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  4. new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
  5. AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBeanFactoryMethod");
  6. bd.setLenientConstructorResolution(false);
  7. try {
  8. xbf.getBean("lenientDependencyTestBeanFactoryMethod");
  9. fail("Should have thrown BeanCreationException");
  10. }
  11. catch (BeanCreationException ex) {
  12. // expected
  13. ex.printStackTrace();
  14. assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
  15. }
  16. }

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

  1. @Test
  2. public void testNonLenientDependencyMatching() {
  3. DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  4. new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
  5. AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean");
  6. bd.setLenientConstructorResolution(false);
  7. try {
  8. xbf.getBean("lenientDependencyTestBean");
  9. fail("Should have thrown BeanCreationException");
  10. }
  11. catch (BeanCreationException ex) {
  12. // expected
  13. ex.printStackTrace();
  14. assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
  15. }
  16. }

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

  1. @Test
  2. public void testAutowireCandidatePatternDoesNotMatch() {
  3. GenericApplicationContext context = new GenericApplicationContext();
  4. ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
  5. scanner.setIncludeAnnotationConfig(true);
  6. scanner.setBeanNameGenerator(new TestBeanNameGenerator());
  7. scanner.setAutowireCandidatePatterns("*NoSuchDao");
  8. scanner.scan(BASE_PACKAGE);
  9. try {
  10. context.refresh();
  11. context.getBean("fooService");
  12. fail("BeanCreationException expected; fooDao should not have been an autowire-candidate");
  13. }
  14. catch (BeanCreationException expected) {
  15. assertTrue(expected.getMostSpecificCause() instanceof NoSuchBeanDefinitionException);
  16. }
  17. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. public <T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
  2. throws BeansException {
  3. String[] beanNames = getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
  4. Map<String, T> result = new LinkedHashMap<String, T>(beanNames.length);
  5. for (String beanName : beanNames) {
  6. try {
  7. result.put(beanName, getBean(beanName, type));
  8. }
  9. catch (BeanCreationException ex) {
  10. Throwable rootCause = ex.getMostSpecificCause();
  11. if (rootCause instanceof BeanCurrentlyInCreationException) {
  12. BeanCreationException bce = (BeanCreationException) rootCause;
  13. if (isCurrentlyInCreation(bce.getBeanName())) {
  14. if (this.logger.isDebugEnabled()) {
  15. this.logger.debug("Ignoring match to currently created bean '" + beanName + "': " +
  16. ex.getMessage());
  17. }
  18. onSuppressedException(ex);
  19. // Ignore: indicates a circular reference when autowiring constructors.
  20. // We want to find matches other than the currently created bean itself.
  21. continue;
  22. }
  23. }
  24. throw ex;
  25. }
  26. }
  27. return result;
  28. }

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

  1. @Test(expected = IllegalArgumentException.class)
  2. public void delimitersNotAllowedWithExpression() throws Throwable {
  3. try {
  4. new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidExpression.xml",
  5. SplitterIntegrationTests.class).close();
  6. }
  7. catch (BeanCreationException e) {
  8. Throwable cause = e.getMostSpecificCause();
  9. assertNotNull(cause);
  10. assertTrue(cause instanceof IllegalArgumentException);
  11. assertTrue(cause.getMessage().contains("'delimiters' property is only available"));
  12. throw cause;
  13. }
  14. }

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

  1. @Test(expected = IllegalArgumentException.class)
  2. public void delimitersNotAllowedWithRef() throws Throwable {
  3. try {
  4. new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidRef.xml",
  5. SplitterIntegrationTests.class).close();
  6. }
  7. catch (BeanCreationException e) {
  8. Throwable cause = e.getMostSpecificCause();
  9. assertNotNull(cause);
  10. assertTrue(cause instanceof IllegalArgumentException);
  11. assertTrue(cause.getMessage().contains("'delimiters' property is only available"));
  12. throw cause;
  13. }
  14. }

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

  1. @Test(expected = IllegalArgumentException.class)
  2. public void delimitersNotAllowedWithInnerBean() throws Throwable {
  3. try {
  4. new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidInnerBean.xml",
  5. SplitterIntegrationTests.class).close();
  6. }
  7. catch (BeanCreationException e) {
  8. Throwable cause = e.getMostSpecificCause();
  9. assertNotNull(cause);
  10. assertTrue(cause instanceof IllegalArgumentException);
  11. assertTrue(cause.getMessage().contains("'delimiters' property is only available"));
  12. throw cause;
  13. }
  14. }

相关文章