Java Code Examples for org.springframework.beans.factory.BeanFactoryUtils#beanOfTypeIncludingAncestors()

The following examples show how to use org.springframework.beans.factory.BeanFactoryUtils#beanOfTypeIncludingAncestors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreeMarkerView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #getApplicationContext
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
				"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 2
Source File: DbFileServlet.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init() throws ServletException {
	WebApplicationContext appCtx = WebApplicationContextUtils
			.getWebApplicationContext(getServletContext());
	dbFileMng = BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx,
			DbFileMng.class);
}
 
Example 3
Source File: SimpleFreeMarkerView.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 自动检测FreeMarkerConfig
 * 
 * @return
 * @throws BeansException
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return (FreeMarkerConfig) BeanFactoryUtils
				.beanOfTypeIncludingAncestors(getApplicationContext(),
						FreeMarkerConfig.class, true, false);
	} catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context "
						+ "(may be inherited): FreeMarkerConfigurer is the usual implementation. "
						+ "This bean may be given any name.", ex);
	}
}
 
Example 4
Source File: AlbumRepositoryPopulator.java    From spring-music with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (event.getApplicationContext().equals(applicationContext)) {
        CrudRepository albumRepository =
                BeanFactoryUtils.beanOfTypeIncludingAncestors(applicationContext, CrudRepository.class);

        if (albumRepository != null && albumRepository.count() == 0) {
            populate(albumRepository);
        }
    }

}
 
Example 5
Source File: ConfigClientAutoConfiguration.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigClientProperties configClientProperties(Environment environment,
		ApplicationContext context) {
	if (context.getParent() != null
			&& BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
					context.getParent(), ConfigClientProperties.class).length > 0) {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(context.getParent(),
				ConfigClientProperties.class);
	}
	ConfigClientProperties client = new ConfigClientProperties(environment);
	return client;
}
 
Example 6
Source File: VelocityView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Autodetect a VelocityEngine via the ApplicationContext.
 * Called if no explicit VelocityEngine has been specified.
 * @return the VelocityEngine to use for VelocityViews
 * @throws BeansException if no VelocityEngine could be found
 * @see #getApplicationContext
 * @see #setVelocityEngine
 */
protected VelocityEngine autodetectVelocityEngine() throws BeansException {
	try {
		VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), VelocityConfig.class, true, false);
		return velocityConfig.getVelocityEngine();
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single VelocityConfig bean in this web application context " +
				"(may be inherited): VelocityConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 7
Source File: FreeMarkerView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #getApplicationContext
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
				"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 8
Source File: ScriptTemplateView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 9
Source File: VelocityView.java    From scoold with Apache License 2.0 5 votes vote down vote up
/**
 * Autodetect a VelocityEngine via the ApplicationContext. Called if no explicit VelocityEngine has been specified.
 *
 * @return the VelocityEngine to use for VelocityViews
 * @throws BeansException if no VelocityEngine could be found
 * @see #getApplicationContext
 * @see #setVelocityEngine
 */
protected VelocityEngine autodetectVelocityEngine() throws BeansException {
	try {
		VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), VelocityConfig.class, true, false);
		return velocityConfig.getVelocityEngine();
	} catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single VelocityConfig bean in this web application context "
				+ "(may be inherited): VelocityConfigurer is the usual implementation. "
				+ "This bean may be given any name.", ex);
	}
}
 
Example 10
Source File: VelocityView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Autodetect a VelocityEngine via the ApplicationContext.
 * Called if no explicit VelocityEngine has been specified.
 * @return the VelocityEngine to use for VelocityViews
 * @throws BeansException if no VelocityEngine could be found
 * @see #getApplicationContext
 * @see #setVelocityEngine
 */
protected VelocityEngine autodetectVelocityEngine() throws BeansException {
	try {
		VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), VelocityConfig.class, true, false);
		return velocityConfig.getVelocityEngine();
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single VelocityConfig bean in this web application context " +
				"(may be inherited): VelocityConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 11
Source File: ScriptTemplateView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 12
Source File: ScriptTemplateView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				getApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 13
Source File: NacosConfigAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
public NacosConfigProperties nacosConfigProperties(ApplicationContext context) {
	if (context.getParent() != null
			&& BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
					context.getParent(), NacosConfigProperties.class).length > 0) {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(context.getParent(),
				NacosConfigProperties.class);
	}
	return new NacosConfigProperties();
}
 
Example 14
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #getApplicationContext
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
				"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 15
Source File: ScriptTemplateView.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 16
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
						"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
						"This bean may be given any name.", ex);
	}
}
 
Example 17
Source File: ScriptTemplateView.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 18
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #getApplicationContext
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
				"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.", ex);
	}
}
 
Example 19
Source File: ScriptTemplateView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected ScriptTemplateConfig autodetectViewConfig() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), ScriptTemplateConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException("Expected a single ScriptTemplateConfig bean in the current " +
				"Servlet web application context or the parent root context: ScriptTemplateConfigurer is " +
				"the usual implementation. This bean may have any name.", ex);
	}
}
 
Example 20
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Autodetect a {@link FreeMarkerConfig} object via the ApplicationContext.
 * @return the Configuration instance to use for FreeMarkerViews
 * @throws BeansException if no Configuration instance could be found
 * @see #setConfiguration
 */
protected FreeMarkerConfig autodetectConfiguration() throws BeansException {
	try {
		return BeanFactoryUtils.beanOfTypeIncludingAncestors(
				obtainApplicationContext(), FreeMarkerConfig.class, true, false);
	}
	catch (NoSuchBeanDefinitionException ex) {
		throw new ApplicationContextException(
				"Must define a single FreeMarkerConfig bean in this web application context " +
						"(may be inherited): FreeMarkerConfigurer is the usual implementation. " +
						"This bean may be given any name.", ex);
	}
}