本文整理汇总了Java中org.springframework.beans.BeanInstantiationException类的典型用法代码示例。如果您正苦于以下问题:Java BeanInstantiationException类的具体用法?Java BeanInstantiationException怎么用?Java BeanInstantiationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanInstantiationException类属于org.springframework.beans包,在下文中一共展示了BeanInstantiationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
throw new BeanInstantiationException(this.getClass(),
"Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
}
if (logger.isDebugEnabled()) {
CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());
config = this.ticketGrantingTicketsCache.getCacheConfiguration();
logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
.getName());
}
}
示例2: instantiateListeners
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
private List<TestExecutionListener> instantiateListeners(List<Class<? extends TestExecutionListener>> classesList) {
List<TestExecutionListener> listeners = new ArrayList<TestExecutionListener>(classesList.size());
for (Class<? extends TestExecutionListener> listenerClass : classesList) {
NoClassDefFoundError ncdfe = null;
try {
listeners.add(BeanUtils.instantiateClass(listenerClass));
}
catch (NoClassDefFoundError err) {
ncdfe = err;
}
catch (BeanInstantiationException ex) {
if (ex.getCause() instanceof NoClassDefFoundError) {
ncdfe = (NoClassDefFoundError) ex.getCause();
}
}
if (ncdfe != null) {
if (logger.isInfoEnabled()) {
logger.info(String.format("Could not instantiate TestExecutionListener [%s]. "
+ "Specify custom listener classes or make the default listener classes "
+ "(and their required dependencies) available. Offending class: [%s]",
listenerClass.getName(), ncdfe.getMessage()));
}
}
}
return listeners;
}
示例3: instantiate
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
/**
* Create a new instance of a dynamically generated subclass implementing the
* required lookups.
* @param ctor constructor to use. If this is {@code null}, use the
* no-arg constructor (no parameterization, or Setter Injection)
* @param args arguments to use for the constructor.
* Ignored if the {@code ctor} parameter is {@code null}.
* @return new instance of the dynamically generated subclass
*/
public Object instantiate(Constructor<?> ctor, Object... args) {
Class<?> subclass = createEnhancedSubclass(this.beanDefinition);
Object instance;
if (ctor == null) {
instance = BeanUtils.instantiate(subclass);
}
else {
try {
Constructor<?> enhancedSubclassConstructor = subclass.getConstructor(ctor.getParameterTypes());
instance = enhancedSubclassConstructor.newInstance(args);
}
catch (Exception ex) {
throw new BeanInstantiationException(this.beanDefinition.getBeanClass(),
"Failed to invoke constructor for CGLIB enhanced subclass [" + subclass.getName() + "]", ex);
}
}
// SPR-10785: set callbacks directly on the instance instead of in the
// enhanced class (via the Enhancer) in order to avoid memory leaks.
Factory factory = (Factory) instance;
factory.setCallbacks(new Callback[] {NoOp.INSTANCE,
new LookupOverrideMethodInterceptor(this.beanDefinition, this.owner),
new ReplaceOverrideMethodInterceptor(this.beanDefinition, this.owner)});
return instance;
}
示例4: postProcessAfterInitialization
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
Class targetClass = bean.getClass();
while(targetClass.getName().contains(CGLIB_SIGNATURE)) {
for(Class interf: targetClass.getInterfaces()) {
if(interf == TransactionalIntercepted.class)
return bean;
}
targetClass = targetClass.getSuperclass();
}
Method[] methods = targetClass.getDeclaredMethods();
for (Method method : methods) {
Transactional txAnnotation = method.getAnnotation(Transactional.class);
if (txAnnotation != null) {
throw new BeanInstantiationException(targetClass, "Bean annotated by @Transactional must be created through DalTransactionManager.create()");
}
}
return bean;
}
示例5: cloneLBHttpSolrClient
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
private static LBHttpSolrClient cloneLBHttpSolrClient(SolrClient solrClient, String core) {
if (solrClient == null) {
return null;
}
LBHttpSolrClient clone = null;
try {
if (VersionUtil.isSolr3XAvailable()) {
clone = cloneSolr3LBHttpServer(solrClient, core);
} else if (VersionUtil.isSolr4XAvailable()) {
clone = cloneSolr4LBHttpServer(solrClient, core);
}
} catch (Exception e) {
throw new BeanInstantiationException(solrClient.getClass(), "Cannot create instace of " + solrClient.getClass()
+ ". ", e);
}
Object o = readField(solrClient, "interval");
if (o != null) {
clone.setAliveCheckInterval(Integer.valueOf(o.toString()).intValue());
}
return clone;
}
示例6: postProcessBeanFactory
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
SimpleStorageResourceLoader simpleStorageResourceLoader = new SimpleStorageResourceLoader(this.amazonS3, this.resourceLoader);
if (this.executor != null) {
simpleStorageResourceLoader.setTaskExecutor(this.executor);
}
try {
simpleStorageResourceLoader.afterPropertiesSet();
} catch (Exception e) {
throw new BeanInstantiationException(SimpleStorageResourceLoader.class, "Error instantiating class", e);
}
this.resourceLoader = new PathMatchingSimpleStorageResourcePatternResolver(this.amazonS3,
simpleStorageResourceLoader, (ResourcePatternResolver) this.resourceLoader);
beanFactory.registerResolvableDependency(ResourceLoader.class, this.resourceLoader);
}
示例7: cloneLBHttpSolrServer
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
private static LBHttpSolrServer cloneLBHttpSolrServer(SolrServer solrServer, String core) {
if (solrServer == null) {
return null;
}
LBHttpSolrServer clone = null;
try {
if (VersionUtil.isSolr3XAvailable()) {
clone = cloneSolr3LBHttpServer(solrServer, core);
} else if (VersionUtil.isSolr4XAvailable()) {
clone = cloneSolr4LBHttpServer(solrServer, core);
}
} catch (MalformedURLException e) {
throw new BeanInstantiationException(solrServer.getClass(), "Cannot create instace of " + solrServer.getClass()
+ ". ", e);
}
Object o = readField(solrServer, "interval");
if (o != null) {
clone.setAliveCheckInterval(Integer.valueOf(o.toString()).intValue());
}
return clone;
}
示例8: afterPropertiesSet
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
logger.info("Setting up Ehcache Ticket Registry...");
if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
throw new BeanInstantiationException(this.getClass(),
"Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
}
if (logger.isDebugEnabled()) {
CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());
config = this.ticketGrantingTicketsCache.getCacheConfiguration();
logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
.getName());
}
}
示例9: afterPropertiesSet
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
logger.info("Setting up Ehcache Ticket Registry...");
if (this.serviceTicketsCache == null || this.ticketGrantingTicketsCache == null) {
throw new BeanInstantiationException(this.getClass(),
"Both serviceTicketsCache and ticketGrantingTicketsCache are required properties.");
}
if (logger.isDebugEnabled()) {
CacheConfiguration config = this.serviceTicketsCache.getCacheConfiguration();
logger.debug("serviceTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("serviceTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("serviceTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("serviceTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("serviceTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("serviceTicketsCache.cacheManager={}", this.serviceTicketsCache.getCacheManager().getName());
config = this.ticketGrantingTicketsCache.getCacheConfiguration();
logger.debug("ticketGrantingTicketsCache.maxElementsInMemory={}", config.getMaxEntriesLocalHeap());
logger.debug("ticketGrantingTicketsCache.maxElementsOnDisk={}", config.getMaxElementsOnDisk());
logger.debug("ticketGrantingTicketsCache.isOverflowToDisk={}", config.isOverflowToDisk());
logger.debug("ticketGrantingTicketsCache.timeToLive={}", config.getTimeToLiveSeconds());
logger.debug("ticketGrantingTicketsCache.timeToIdle={}", config.getTimeToIdleSeconds());
logger.debug("ticketGrantingTicketsCache.cacheManager={}", this.ticketGrantingTicketsCache.getCacheManager()
.getName());
}
}
示例10: instantiate
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) {
// Don't override the class with CGLIB if no overrides.
if (beanDefinition.getMethodOverrides().isEmpty()) {
Constructor<?> constructorToUse;
synchronized (beanDefinition.constructorArgumentLock) {
constructorToUse = (Constructor<?>) beanDefinition.resolvedConstructorOrFactoryMethod;
if (constructorToUse == null) {
final Class<?> clazz = beanDefinition.getBeanClass();
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
try {
if (System.getSecurityManager() != null) {
constructorToUse = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>() {
@Override
public Constructor<?> run() throws Exception {
return clazz.getDeclaredConstructor((Class[]) null);
}
});
}
else {
constructorToUse = clazz.getDeclaredConstructor((Class[]) null);
}
beanDefinition.resolvedConstructorOrFactoryMethod = constructorToUse;
}
catch (Exception ex) {
throw new BeanInstantiationException(clazz, "No default constructor found", ex);
}
}
}
return BeanUtils.instantiateClass(constructorToUse);
}
else {
// Must generate CGLIB subclass.
return instantiateWithMethodInjection(beanDefinition, beanName, owner);
}
}
示例11: instantiate
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
/**
* Create a new instance of a dynamically generated subclass implementing the
* required lookups.
* @param ctor constructor to use. If this is {@code null}, use the
* no-arg constructor (no parameterization, or Setter Injection)
* @param args arguments to use for the constructor.
* Ignored if the {@code ctor} parameter is {@code null}.
* @return new instance of the dynamically generated subclass
*/
Object instantiate(Constructor<?> ctor, Object[] args) {
Class<?> subclass = createEnhancedSubclass(this.beanDefinition);
Object instance;
if (ctor == null) {
instance = BeanUtils.instantiate(subclass);
}
else {
try {
Constructor<?> enhancedSubclassConstructor = subclass.getConstructor(ctor.getParameterTypes());
instance = enhancedSubclassConstructor.newInstance(args);
}
catch (Exception e) {
throw new BeanInstantiationException(this.beanDefinition.getBeanClass(), String.format(
"Failed to invoke construcor for CGLIB enhanced subclass [%s]", subclass.getName()), e);
}
}
// SPR-10785: set callbacks directly on the instance instead of in the
// enhanced class (via the Enhancer) in order to avoid memory leaks.
Factory factory = (Factory) instance;
factory.setCallbacks(new Callback[] { NoOp.INSTANCE,//
new LookupOverrideMethodInterceptor(beanDefinition, owner),//
new ReplaceOverrideMethodInterceptor(beanDefinition, owner) });
return instance;
}
示例12: testProxyingDecoratorNoInstance
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Test
public void testProxyingDecoratorNoInstance() throws Exception {
String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class);
assertTrue(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance"));
assertEquals(ApplicationListener.class, this.beanFactory.getType("debuggingTestBeanNoInstance"));
try {
this.beanFactory.getBean("debuggingTestBeanNoInstance");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause() instanceof BeanInstantiationException);
}
}
示例13: getHandlerNoBeanFactory
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Test(expected=BeanInstantiationException.class)
public void getHandlerNoBeanFactory() {
BeanCreatingHandlerProvider<EchoHandler> provider =
new BeanCreatingHandlerProvider<EchoHandler>(EchoHandler.class);
provider.getHandler();
}
示例14: instantiate
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public Object instantiate(RootBeanDefinition bd, String beanName, BeanFactory owner) {
// Don't override the class with CGLIB if no overrides.
if (bd.getMethodOverrides().isEmpty()) {
Constructor<?> constructorToUse;
synchronized (bd.constructorArgumentLock) {
constructorToUse = (Constructor<?>) bd.resolvedConstructorOrFactoryMethod;
if (constructorToUse == null) {
final Class<?> clazz = bd.getBeanClass();
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
try {
if (System.getSecurityManager() != null) {
constructorToUse = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>() {
@Override
public Constructor<?> run() throws Exception {
return clazz.getDeclaredConstructor((Class[]) null);
}
});
}
else {
constructorToUse = clazz.getDeclaredConstructor((Class[]) null);
}
bd.resolvedConstructorOrFactoryMethod = constructorToUse;
}
catch (Exception ex) {
throw new BeanInstantiationException(clazz, "No default constructor found", ex);
}
}
}
return BeanUtils.instantiateClass(constructorToUse);
}
else {
// Must generate CGLIB subclass.
return instantiateWithMethodInjection(bd, beanName, owner);
}
}
示例15: postProcessBeforeInitialization
import org.springframework.beans.BeanInstantiationException; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
// System.err.println("postProcessBeforeInitialization:" + beanName);
Class<?> clazz = bean.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Value annotation = field.getAnnotation(Value.class);
if (annotation == null) {
continue;
}
field.setAccessible(true);
Object value = resolveValue(annotation, field);
if (value == null) {
continue;
}
try {
field.set(bean, value);
FieldInfo fieldInfo = new FieldInfo();
fieldInfo.setBean(bean);
fieldInfo.setField(field);
fieldList.add(fieldInfo);
}
catch (IllegalAccessException e) {
throw new BeanInstantiationException(clazz, e.getMessage(), e);
}
}
return bean;
}