当前位置: 首页>>代码示例>>Java>>正文


Java CannotLoadBeanClassException类代码示例

本文整理汇总了Java中org.springframework.beans.factory.CannotLoadBeanClassException的典型用法代码示例。如果您正苦于以下问题:Java CannotLoadBeanClassException类的具体用法?Java CannotLoadBeanClassException怎么用?Java CannotLoadBeanClassException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CannotLoadBeanClassException类属于org.springframework.beans.factory包,在下文中一共展示了CannotLoadBeanClassException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClassNotFoundWithDefaultBeanClassLoader

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * When using a BeanFactory. singletons are of course not pre-instantiated.
 * So rubbish class names in bean defs must now not be 'resolved' when the
 * bean def is being parsed, 'cos everything on a bean def is now lazy, but
 * must rather only be picked up when the bean is instantiated.
 */
@Test
public void testClassNotFoundWithDefaultBeanClassLoader() {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CLASS_NOT_FOUND_CONTEXT);
	// cool, no errors, so the rubbish class name in the bean def was not resolved
	try {
		// let's resolve the bean definition; must blow up
		factory.getBean("classNotFound");
		fail("Must have thrown a CannotLoadBeanClassException");
	}
	catch (CannotLoadBeanClassException ex) {
		assertTrue(ex.getResourceDescription().indexOf("classNotFound.xml") != -1);
		assertTrue(ex.getCause() instanceof ClassNotFoundException);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:XmlBeanFactoryTests.java

示例2: autodetect

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(AutodetectCallback callback) {
	Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount());
	beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
	}
	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
					if (!this.beans.containsValue(beanName) && (beanInstance == null ||
							!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isInfoEnabled()) {
							logger.info("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:45,代码来源:MBeanExporter.java

示例3: publishEndpoints

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Publish all {@link javax.jws.WebService} annotated beans in the
 * containing BeanFactory.
 * @see #publishEndpoint
 */
public void publishEndpoints() {
	Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount());
	beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
	}
	for (String beanName : beanNames) {
		try {
			Class<?> type = this.beanFactory.getType(beanName);
			if (type != null && !type.isInterface()) {
				WebService wsAnnotation = type.getAnnotation(WebService.class);
				WebServiceProvider wsProviderAnnotation = type.getAnnotation(WebServiceProvider.class);
				if (wsAnnotation != null || wsProviderAnnotation != null) {
					Endpoint endpoint = createEndpoint(this.beanFactory.getBean(beanName));
					if (this.endpointProperties != null) {
						endpoint.setProperties(this.endpointProperties);
					}
					if (this.executor != null) {
						endpoint.setExecutor(this.executor);
					}
					if (wsAnnotation != null) {
						publishEndpoint(endpoint, wsAnnotation);
					}
					else {
						publishEndpoint(endpoint, wsProviderAnnotation);
					}
					this.publishedEndpoints.add(endpoint);
				}
			}
		}
		catch (CannotLoadBeanClassException ex) {
			// ignore beans where the class is not resolvable
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:AbstractJaxWsServiceExporter.java

示例4: getBeanClass

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Get bean class from bean class name.
 * @param beanName Bean name
 * @param beanClassName Bean class naem (not null)
 * @param classLoader ClassLoader to use (null for default class loader)
 * @return Bean class
 * @throws CannotLoadBeanClassException Class name not found in given ClassLoader
 */
private static Class<?> getBeanClass(final String beanName, final String beanClassName, ClassLoader classLoader)
		throws CannotLoadBeanClassException {
	ObjectUtils.argumentNotNull(beanClassName, "Bean class name must be not null");
	try {
		return ClassUtils.forName(beanClassName, classLoader);
	} catch (ClassNotFoundException e) {
		throw new CannotLoadBeanClassException(BeanRegistryUtils.class.getName(), beanName, beanClassName, e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:18,代码来源:BeanRegistryUtils.java

示例5: autodetect

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Performs the actual autodetection process, delegating to an
 * {@code AutodetectCallback} instance to vote on the inclusion of a
 * given bean.
 * @param callback the {@code AutodetectCallback} to use when deciding
 * whether to include a bean or not
 */
private void autodetect(AutodetectCallback callback) {
	Set<String> beanNames = new LinkedHashSet<String>(this.beanFactory.getBeanDefinitionCount());
	beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
	if (this.beanFactory instanceof ConfigurableBeanFactory) {
		beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
	}
	for (String beanName : beanNames) {
		if (!isExcluded(beanName) && !isBeanDefinitionAbstract(this.beanFactory, beanName)) {
			try {
				Class<?> beanClass = this.beanFactory.getType(beanName);
				if (beanClass != null && callback.include(beanClass, beanName)) {
					boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
					Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
					if (!ScopedProxyUtils.isScopedTarget(beanName) && !this.beans.containsValue(beanName) &&
							(beanInstance == null ||
									!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
						// Not already registered for JMX exposure.
						this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
						if (logger.isInfoEnabled()) {
							logger.info("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
						}
					}
					else {
						if (logger.isDebugEnabled()) {
							logger.debug("Bean with name '" + beanName + "' is already registered for JMX exposure");
						}
					}
				}
			}
			catch (CannotLoadBeanClassException ex) {
				if (this.allowEagerInit) {
					throw ex;
				}
				// otherwise ignore beans where the class is not resolvable
			}
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:46,代码来源:MBeanExporter.java

示例6: testContextWithInvalidLazyClass

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
@Test
public void testContextWithInvalidLazyClass() {
	ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(INVALID_CLASS_CONTEXT, getClass());
	assertTrue(ctx.containsBean("someMessageSource"));
	try {
		ctx.getBean("someMessageSource");
		fail("Should have thrown CannotLoadBeanClassException");
	}
	catch (CannotLoadBeanClassException ex) {
		assertTrue(ex.contains(ClassNotFoundException.class));
	}
	ctx.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ClassPathXmlApplicationContextTests.java

示例7: retrieveClassByName

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Возвращает название класса по его имени
 *
 * @param className название класса
 * @return Возвращает класс
 */
private static Class<?> retrieveClassByName(String className) {
    try {
        return Class.forName(className);
    } catch (ClassNotFoundException ex) {
        throw new CannotLoadBeanClassException(null, null, className, ex);
    }
}
 
开发者ID:hflabs,项目名称:perecoder,代码行数:14,代码来源:PropertiesToDataSourceDescriptorConverter.java

示例8: testContextWithInvalidLazyClass

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
@Test
public void testContextWithInvalidLazyClass() {
	ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
			INVALID_CLASS_CONTEXT, getClass());
	assertTrue(ctx.containsBean("someMessageSource"));
	try {
		ctx.getBean("someMessageSource");
		fail("Should have thrown CannotLoadBeanClassException");
	}
	catch (CannotLoadBeanClassException ex) {
		assertTrue(ex.contains(ClassNotFoundException.class));
	}
	ctx.close();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:15,代码来源:ClassPathXmlApplicationContextTests.java

示例9: findClassByName

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
public static Class<?> findClassByName(String className, String beanName, ParserContext parserContext) {
    String description = parserContext.getReaderContext().getResource().getDescription();
    try {
        return Class.forName(className);
    } catch (ClassNotFoundException ex) {
        throw new CannotLoadBeanClassException(description, beanName, className, ex);
    }
}
 
开发者ID:jirutka,项目名称:spring-modular,代码行数:9,代码来源:ParserUtils.java

示例10: initImplementorManagerAndImplementorBeanNamesMap

import org.springframework.beans.factory.CannotLoadBeanClassException; //导入依赖的package包/类
/**
 * Init {@linkplain #implementorManager} and
 * {@linkplain #implementorBeanNamesMap}.
 * <p>
 * Synchronization for {@linkplain #implementorManager} and
 * {@linkplain #implementorBeanNamesMap} are not necessary, because they are
 * initialized in #setBeanFactory(BeanFactory) which happens before any
 * other actions.
 * </p>
 * 
 * @throws BeansException
 */
protected void initImplementorManagerAndImplementorBeanNamesMap()
		throws BeansException
{
	String[] allBeanNames = beanFactory.getBeanDefinitionNames();

	for (int i = 0; i < allBeanNames.length; i++)
	{
		String beanName = allBeanNames[i];

		Class<?> beanClass = null;

		BeanDefinition beanDefinition = this.beanFactory
				.getBeanDefinition(beanName);
		String beanClassName = beanDefinition.getBeanClassName();

		try
		{
			beanClass = Class.forName(beanClassName);
		}
		catch (ClassNotFoundException e)
		{
			throw new CannotLoadBeanClassException(
					beanDefinition.getResourceDescription(), beanName,
					beanClassName, e);
		}

		List<String> implementorBeanNames = this.implementorBeanNamesMap
				.get(beanClass);
		if (implementorBeanNames == null)
		{
			implementorBeanNames = new ArrayList<String>();
			this.implementorBeanNamesMap.put(beanClass,
					implementorBeanNames);
		}
		implementorBeanNames.add(beanName);

		// Add itself, fix missing itself as an implementor when auto wired
		// class is not abstract
		this.implementorManager.addFor(beanClass, beanClass);
		this.implementorManager.add(beanClass);
	}
}
 
开发者ID:ximplementation,项目名称:ximplementation-spring,代码行数:55,代码来源:ImplementeeBeanCreationPostProcessor.java


注:本文中的org.springframework.beans.factory.CannotLoadBeanClassException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。