Search in sources :

Example 1 with MissingWebServerFactoryBeanException

use of cn.taketoday.framework.web.context.MissingWebServerFactoryBeanException in project today-framework by TAKETODAY.

the class ServletWebServerApplicationContext method getWebServerFactory.

/**
 * Returns the {@link ServletWebServerFactory} that should be used to create the
 * embedded {@link WebServer}. By default this method searches for a suitable bean in
 * the context itself.
 *
 * @return a {@link ServletWebServerFactory} (never {@code null})
 */
protected ServletWebServerFactory getWebServerFactory() {
    // Use bean names so that we don't consider the hierarchy
    StandardBeanFactory beanFactory = getBeanFactory();
    Set<String> beanNames = beanFactory.getBeanNamesForType(ServletWebServerFactory.class);
    if (beanNames.size() == 0) {
        throw new MissingWebServerFactoryBeanException(getClass(), ServletWebServerFactory.class, ApplicationType.SERVLET_WEB);
    }
    if (beanNames.size() > 1) {
        throw new ApplicationContextException("Unable to start ServletWebServerApplicationContext due to multiple " + "ServletWebServerFactory beans : " + StringUtils.collectionToCommaDelimitedString(beanNames));
    }
    return beanFactory.getBean(CollectionUtils.firstElement(beanNames), ServletWebServerFactory.class);
}
Also used : MissingWebServerFactoryBeanException(cn.taketoday.framework.web.context.MissingWebServerFactoryBeanException) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) ApplicationContextException(cn.taketoday.context.ApplicationContextException)

Example 2 with MissingWebServerFactoryBeanException

use of cn.taketoday.framework.web.context.MissingWebServerFactoryBeanException in project today-infrastructure by TAKETODAY.

the class ServletWebServerApplicationContext method getWebServerFactory.

/**
 * Returns the {@link ServletWebServerFactory} that should be used to create the
 * embedded {@link WebServer}. By default this method searches for a suitable bean in
 * the context itself.
 *
 * @return a {@link ServletWebServerFactory} (never {@code null})
 */
protected ServletWebServerFactory getWebServerFactory() {
    // Use bean names so that we don't consider the hierarchy
    StandardBeanFactory beanFactory = getBeanFactory();
    Set<String> beanNames = beanFactory.getBeanNamesForType(ServletWebServerFactory.class);
    if (beanNames.size() == 0) {
        throw new MissingWebServerFactoryBeanException(getClass(), ServletWebServerFactory.class, ApplicationType.SERVLET_WEB);
    }
    if (beanNames.size() > 1) {
        throw new ApplicationContextException("Unable to start ServletWebServerApplicationContext due to multiple " + "ServletWebServerFactory beans : " + StringUtils.collectionToCommaDelimitedString(beanNames));
    }
    return beanFactory.getBean(CollectionUtils.firstElement(beanNames), ServletWebServerFactory.class);
}
Also used : MissingWebServerFactoryBeanException(cn.taketoday.framework.web.context.MissingWebServerFactoryBeanException) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) ApplicationContextException(cn.taketoday.context.ApplicationContextException)

Aggregations

StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 ApplicationContextException (cn.taketoday.context.ApplicationContextException)2 MissingWebServerFactoryBeanException (cn.taketoday.framework.web.context.MissingWebServerFactoryBeanException)2