本文整理匯總了Java中org.springframework.beans.FatalBeanException類的典型用法代碼示例。如果您正苦於以下問題:Java FatalBeanException類的具體用法?Java FatalBeanException怎麽用?Java FatalBeanException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FatalBeanException類屬於org.springframework.beans包,在下文中一共展示了FatalBeanException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureFeature
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
if (feature instanceof JsonParser.Feature) {
objectMapper.configure((JsonParser.Feature) feature, enabled);
}
else if (feature instanceof JsonGenerator.Feature) {
objectMapper.configure((JsonGenerator.Feature) feature, enabled);
}
else if (feature instanceof SerializationFeature) {
objectMapper.configure((SerializationFeature) feature, enabled);
}
else if (feature instanceof DeserializationFeature) {
objectMapper.configure((DeserializationFeature) feature, enabled);
}
else if (feature instanceof MapperFeature) {
objectMapper.configure((MapperFeature) feature, enabled);
}
else {
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
}
}
示例2: createApplicationContext
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
protected ApplicationContext createApplicationContext(String uri) throws MalformedURLException {
Resource resource = Utils.resourceFromString(uri);
LOG.debug("Using " + resource + " from " + uri);
try {
return new ResourceXmlApplicationContext(resource) {
@Override
protected ConfigurableEnvironment createEnvironment() {
return new ReversePropertySourcesStandardServletEnvironment();
}
@Override
protected void initPropertySources() {
WebApplicationContextUtils.initServletPropertySources(getEnvironment().getPropertySources(),
ServletContextHolder.getServletContext());
}
};
} catch (FatalBeanException errorToLog) {
LOG.error("Failed to load: " + resource + ", reason: " + errorToLog.getLocalizedMessage(), errorToLog);
throw errorToLog;
}
}
示例3: release
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
public void release() throws FatalBeanException {
synchronized (bfgInstancesByKey) {
BeanFactory savedRef = this.groupContextRef;
if (savedRef != null) {
this.groupContextRef = null;
BeanFactoryGroup bfg = bfgInstancesByObj.get(savedRef);
if (bfg != null) {
bfg.refCount--;
if (bfg.refCount == 0) {
destroyDefinition(savedRef, resourceLocation);
bfgInstancesByKey.remove(resourceLocation);
bfgInstancesByObj.remove(savedRef);
}
}
else {
// This should be impossible.
logger.warn("Tried to release a SingletonBeanFactoryLocator group definition " +
"more times than it has actually been used. Resource name [" + resourceLocation + "]");
}
}
}
}
示例4: configureFeature
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
private void configureFeature(Object feature, boolean enabled) {
if (feature instanceof JsonParser.Feature) {
this.objectMapper.configure((JsonParser.Feature) feature, enabled);
}
else if (feature instanceof JsonGenerator.Feature) {
this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
}
else if (feature instanceof SerializationFeature) {
this.objectMapper.configure((SerializationFeature) feature, enabled);
}
else if (feature instanceof DeserializationFeature) {
this.objectMapper.configure((DeserializationFeature) feature, enabled);
}
else if (feature instanceof MapperFeature) {
this.objectMapper.configure((MapperFeature) feature, enabled);
}
else {
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
}
}
示例5: afterPropertiesSet
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
/**
* Is called by the Spring container after all properties have been set. <br>
* It is implemented in order to initialize the beanClass field correctly and to make sure
* that either the bean id or the bean itself have been set on this creator.
* @see org.springframework.beans.factory.InitializingBean
*/
public void afterPropertiesSet()
{
// make sure that either the bean or the beanId have been set correctly
if (bean != null) {
this.beanClass = bean.getClass();
} else if (beanId != null) {
this.beanClass = applicationContext.getType(beanId);
} else {
throw new FatalBeanException(
"You should either set the bean property directly or set the beanId property");
}
// make sure to handle cglib proxies correctly
if(AopUtils.isCglibProxyClass(this.beanClass)) {
this.beanClass = this.beanClass.getSuperclass();
}
}
示例6: getMatchOutcome
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String prefix = (String) attribute(metadata, "prefix");
Class<?> value = (Class<?>) attribute(metadata, "value");
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
try {
new Binder(ConfigurationPropertySources.from(environment.getPropertySources()))
.bind(prefix, Bindable.of(value))
.orElseThrow(
() -> new FatalBeanException("Could not bind DataSourceSettings properties"));
return new ConditionOutcome(true, String.format("Map property [%s] is not empty", prefix));
} catch (Exception e) {
//ignore
}
return new ConditionOutcome(false, String.format("Map property [%s] is empty", prefix));
}
示例7: postProcessAfterInitialization
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
try {
Class<?> wrapped = AopUtils.getTargetClass(bean);
if (!isSpring(wrapped)) {
Class<?> declaring = AnnotationUtils.findAnnotationDeclaringClass(Steps.class, wrapped);
if (null != declaring) {
processStepsBean(beanName, wrapped);
}
}
return bean;
}
catch (Exception e) {
throw new FatalBeanException("unable to processAnnotationContainer @Steps beans", e);
}
}
示例8: afterPropertiesSet
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
/**
* Is called by the Spring container after all properties have been set. <br>
* It is implemented in order to initialize the beanClass field correctly and to make sure
* that either the bean id or the bean itself have been set on this creator.
* @see org.springframework.beans.factory.InitializingBean
*/
public void afterPropertiesSet()
{
// make sure that either the bean or the beanId have been set correctly
if (bean != null)
{
this.beanClass = bean.getClass();
}
else if (beanId != null)
{
this.beanClass = beanFactory.getType(beanId);
}
else
{
throw new FatalBeanException("You should either set the bean property directly or set the beanId property");
}
// make sure to handle cglib proxies correctly
if (ClassUtils.isCglibProxyClass(this.beanClass))
{
this.beanClass = this.beanClass.getSuperclass();
}
}
示例9: resolveBeanClassname
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
/**
* Tries to obtain the beanClassName from the definition and if that fails tries to get it from
* the parent (and even parent BeanFactory if we have to).
*
* @param definition a non null instance
* @param registry a non null instance
* @return class name or null if not found
*/
protected String resolveBeanClassname(BeanDefinition definition, BeanDefinitionRegistry registry)
{
String beanClassName = definition.getBeanClassName();
while(!StringUtils.hasText(beanClassName))
{
try
{
Method m = definition.getClass().getMethod("getParentName", new Class[0]);
String parentName = (String) m.invoke(definition, new Object[0]);
BeanDefinition parentDefinition = findParentDefinition(parentName, registry);
beanClassName = parentDefinition.getBeanClassName();
definition = parentDefinition;
} catch (Exception e)
{
throw new FatalBeanException("No parent bean could be found for " + definition, e);
}
}
return beanClassName;
}
示例10: handlerBeanNotFound
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Test
public void handlerBeanNotFound() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext root = new XmlWebApplicationContext();
root.setServletContext(sc);
root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"});
root.refresh();
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("map2err");
wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"});
try {
wac.refresh();
fail("Should have thrown NoSuchBeanDefinitionException");
}
catch (FatalBeanException ex) {
NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
assertEquals("mainControlle", nestedEx.getBeanName());
}
}
示例11: validateDeclaredRemotingException
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
private void validateDeclaredRemotingException(Method method, Class<?> clazz) throws IllegalStateException {
Class<?>[] exceptionTypeArray = method.getExceptionTypes();
boolean located = false;
for (int i = 0; i < exceptionTypeArray.length; i++) {
Class<?> exceptionType = exceptionTypeArray[i];
if (RemotingException.class.isAssignableFrom(exceptionType)) {
located = true;
break;
}
}
if (located) {
throw new FatalBeanException(String.format(
"The method(%s) shouldn't be declared to throw a remote exception: org.bytesoft.compensable.RemotingException!",
method));
}
}
示例12: processBeanDefinition
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd, String beanClassName, String definitionName) throws FatalBeanException {
if (beanFactory instanceof DefaultListableBeanFactory) {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
try {
final WebScript webScript = AnnotationUtils.findAnnotation(Class.forName(beanClassName), WebScript.class);
if (webScript != null) {
String beanName = webScript.value();
if (StringUtils.hasText(beanName)) {
final String webScriptName = "webscript." + beanName + "." + webScript.method().toString().toLowerCase();
factory.removeBeanDefinition(definitionName);
factory.registerBeanDefinition(webScriptName, bd);
} else {
throw new FatalBeanException(String.format("%s is @WebScript annotated, but no value set.", beanClassName));
}
}
} catch (ClassNotFoundException e) {
logger.warn(String.format("ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'", definitionName, beanClassName));
}
} else {
logger.error(String.format("Unable to register '%s' as webscript because beanFactory is not instance of 'DefaultListableBeanFactory'", definitionName));
}
}
示例13: processBeanDefinition
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
@Override
protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd, String beanClassName, String definitionName) throws FatalBeanException {
try {
final ChildOf childOf = AnnotationUtils.findAnnotation(Class.forName(beanClassName), ChildOf.class);
if (childOf != null) {
final String parentName = childOf.value();
if (StringUtils.hasText(parentName)) {
bd.setParentName(parentName);
} else {
throw new FatalBeanException(String.format("%s is @ChildOf annotated, but no value set.", beanClassName));
}
}
} catch (ClassNotFoundException e) {
logger.warn(String.format("ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'", definitionName, beanClassName));
}
}
示例14: postProcessBeanFactory
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
for (String definitionName : beanDefinitionNames) {
try {
final BeanDefinition bd = beanFactory.getBeanDefinition(definitionName);
final String beanClassName = bd.getBeanClassName();
if (StringUtils.hasText(beanClassName)) {
try {
processBeanDefinition(beanFactory, bd, beanClassName, definitionName);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new FatalBeanException("Unknown class defined.", e);
}
}
} catch (NoSuchBeanDefinitionException ex) {
logger.warn(ex.getMessage());
continue;
}
}
}
示例15: MergeClassPathXMLApplicationContext
import org.springframework.beans.FatalBeanException; //導入依賴的package包/類
/**
* Create a new MergeClassPathXMLApplicationContext, loading the definitions from the given definitions. Note,
* all sourceLocation files will be merged using standard Spring configuration override rules. However, the patch
* files are fully merged into the result of the sourceLocations simple merge. Patch merges are first executed according
* to beans with the same id. Subsequent merges within a bean are executed against tagnames - ignoring any
* further id attributes.
*
* @param sourceLocations array of relative (or absolute) paths within the class path for the source application context files
* @param patchLocations array of relative (or absolute) paths within the class path for the patch application context files
* @param parent the parent context
* @throws BeansException
*/
public MergeClassPathXMLApplicationContext(String[] sourceLocations, String[] patchLocations, ApplicationContext parent) throws BeansException {
this(parent);
ResourceInputStream[] sources = new ResourceInputStream[sourceLocations.length];
for (int j=0;j<sourceLocations.length;j++){
sources[j] = new ResourceInputStream(getClassLoader(parent).getResourceAsStream(sourceLocations[j]), sourceLocations[j]);
}
ResourceInputStream[] patches = new ResourceInputStream[patchLocations.length];
for (int j=0;j<patches.length;j++){
patches[j] = new ResourceInputStream(getClassLoader(parent).getResourceAsStream(patchLocations[j]), patchLocations[j]);
}
ImportProcessor importProcessor = new ImportProcessor(this);
try {
sources = importProcessor.extract(sources);
patches = importProcessor.extract(patches);
} catch (MergeException e) {
throw new FatalBeanException("Unable to merge source and patch locations", e);
}
this.configResources = new MergeApplicationContextXmlConfigResource().getConfigResources(sources, patches);
refresh();
}