本文整理了Java中org.springframework.beans.factory.BeanCreationException.getCause()
方法的一些代码示例,展示了BeanCreationException.getCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanCreationException.getCause()
方法的具体详情如下:
包路径:org.springframework.beans.factory.BeanCreationException
类名称:BeanCreationException
方法名:getCause
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInvalidBeanNameReference() throws Exception {
try {
this.beanFactory.getBean("jumble2");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof BeanDefinitionStoreException);
assertTrue(ex.getCause().getMessage().contains("rod2"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void equivalentMappingsWithSameMethodName() throws Exception {
try {
initServletWithControllers(ChildController.class);
fail("Expected 'method already mapped' error");
}
catch (BeanCreationException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
assertTrue(e.getCause().getMessage().contains("Ambiguous mapping"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithRequiredPropertyOmitted() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder
.genericBeanDefinition(RequiredTestBean.class)
.addPropertyValue("name", "Rob Harrop")
.addPropertyValue("favouriteColour", "Blue")
.addPropertyValue("jobTitle", "Grand Poobah")
.getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Property"));
assertTrue(message.contains("age"));
assertTrue(message.contains("testBean"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testSpringInitBean() throws Exception {
try {
beanFactory.getBean("spring-init");
fail("expected security exception");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithStaticFactoryMethod() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder
.genericBeanDefinition(RequiredTestBean.class)
.setFactoryMethod("create")
.addPropertyValue("name", "Rob Harrop")
.addPropertyValue("favouriteColour", "Blue")
.addPropertyValue("jobTitle", "Grand Poobah")
.getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Property"));
assertTrue(message.contains("age"));
assertTrue(message.contains("testBean"));
}
}
代码示例来源:origin: spring-projects/spring-framework
private void testDoubleTargetSourceIsRejected(String name) {
try {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS));
bf.getBean(name);
fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property");
}
catch (BeanCreationException ex) {
// Root cause of the problem must be an AOP exception
AopConfigException aex = (AopConfigException) ex.getCause();
assertTrue(aex.getMessage().contains("TargetSource"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCustomInitBean() throws Exception {
try {
beanFactory.getBean("custom-init");
fail("expected security exception");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCustomFactoryObject() throws Exception {
try {
beanFactory.getBean("spring-factory");
fail("expected security exception");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithThreeRequiredPropertiesOmitted() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder
.genericBeanDefinition(RequiredTestBean.class)
.addPropertyValue("name", "Rob Harrop")
.getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Properties"));
assertTrue(message.contains("age"));
assertTrue(message.contains("favouriteColour"));
assertTrue(message.contains("jobTitle"));
assertTrue(message.contains("testBean"));
}
}
代码示例来源:origin: spring-projects/spring-framework
public void xtestTypeMismatch() {
try {
getBeanFactory().getBean("typeMismatch");
fail("Shouldn't succeed with type mismatch");
}
catch (BeanCreationException wex) {
assertEquals("typeMismatch", wex.getBeanName());
assertTrue(wex.getCause() instanceof PropertyBatchUpdateException);
PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause();
// Further tests
assertTrue("Has one error ", ex.getExceptionCount() == 1);
assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null);
assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithCustomAnnotation() {
try {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
BeanDefinition beanDef = BeanDefinitionBuilder
.genericBeanDefinition(RequiredTestBean.class)
.getBeanDefinition();
factory.registerBeanDefinition("testBean", beanDef);
RequiredAnnotationBeanPostProcessor rabpp = new RequiredAnnotationBeanPostProcessor();
rabpp.setRequiredAnnotationType(MyRequired.class);
factory.addBeanPostProcessor(rabpp);
factory.preInstantiateSingletons();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
String message = ex.getCause().getMessage();
assertTrue(message.contains("Property"));
assertTrue(message.contains("name"));
assertTrue(message.contains("testBean"));
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testJobLaunchingGatewayNoJobLauncher() throws Exception {
try {
setUp("JobLaunchingGatewayParserTestsNoJobLauncher-context.xml", getClass());
}
catch(BeanCreationException e) {
assertEquals("No bean named 'jobLauncher' available", e.getCause().getMessage());
return;
}
fail("Expected a NoSuchBeanDefinitionException to be thrown.");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() {
try {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS));
bf.getBean("targetSourceNotLast");
fail("TargetSource or non-advised object must be last in interceptorNames");
}
catch (BeanCreationException ex) {
// Root cause of the problem must be an AOP exception
AopConfigException aex = (AopConfigException) ex.getCause();
assertTrue(aex.getMessage().contains("interceptorNames"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void testServletContextAttributeFactoryBeanWithAttributeNotFound() {
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("attributeName", "myAttr");
wac.registerSingleton("importedAttr", ServletContextAttributeFactoryBean.class, pvs);
try {
wac.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
assertTrue(ex.getCause() instanceof IllegalStateException);
assertTrue(ex.getCause().getMessage().contains("myAttr"));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void testServletContextParameterFactoryBeanWithAttributeNotFound() {
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("initParamName", "myParam");
wac.registerSingleton("importedParam", ServletContextParameterFactoryBean.class, pvs);
try {
wac.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
assertTrue(ex.getCause() instanceof IllegalStateException);
assertTrue(ex.getCause().getMessage().contains("myParam"));
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Globals must be followed by a target.
*/
@Test
public void testGlobalsWithoutTarget() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INVALID_CONTEXT, CLASS));
try {
bf.getBean("globalsWithoutTarget");
fail("Should require target name");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof AopConfigException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPossibleMatches() {
try {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("ag", "foobar");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("tb", bd);
lbf.getBean("tb");
fail("Should throw exception on invalid property");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof NotWritablePropertyException);
NotWritablePropertyException cause = (NotWritablePropertyException) ex.getCause();
// expected
assertEquals(1, cause.getPossibleMatches().length);
assertEquals("age", cause.getPossibleMatches()[0]);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Test that if a custom initializer throws an exception, it's handled correctly
*/
@Test
public void testInitMethodThrowsException() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
try {
xbf.getBean("init-method2");
fail();
}
catch (BeanCreationException ex) {
assertTrue(ex.getResourceDescription().contains("initializers.xml"));
assertEquals("init-method2", ex.getBeanName());
assertTrue(ex.getCause() instanceof IOException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testDefaultLazyInit() throws Exception {
InitAndIB.constructed = false;
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT);
assertFalse(InitAndIB.constructed);
xbf.preInstantiateSingletons();
assertTrue(InitAndIB.constructed);
try {
xbf.getBean("lazy-and-bad");
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof IOException);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void eventListenerWorksWithCustomScope() throws Exception {
load(CustomScopeTestBean.class);
CustomScope customScope = new CustomScope();
this.context.getBeanFactory().registerScope("custom", customScope);
CustomScopeTestBean proxy = this.context.getBean(CustomScopeTestBean.class);
assertTrue("bean should be a cglib proxy", AopUtils.isCglibProxy(proxy));
this.eventCollector.assertNoEventReceived(proxy.getId());
this.context.publishEvent(new ContextRefreshedEvent(this.context));
this.eventCollector.assertNoEventReceived(proxy.getId());
customScope.active = false;
this.context.publishEvent(new ContextRefreshedEvent(this.context));
customScope.active = true;
this.eventCollector.assertNoEventReceived(proxy.getId());
TestEvent event = new TestEvent();
this.context.publishEvent(event);
this.eventCollector.assertEvent(proxy.getId(), event);
this.eventCollector.assertTotalEventsCount(1);
try {
customScope.active = false;
this.context.publishEvent(new TestEvent());
fail("Should have thrown IllegalStateException");
}
catch (BeanCreationException ex) {
// expected
assertTrue(ex.getCause() instanceof IllegalStateException);
}
}
内容来源于网络,如有侵权,请联系作者删除!