org.springframework.beans.factory.BeanInitializationException Java Examples

The following examples show how to use org.springframework.beans.factory.BeanInitializationException. 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: BeanValidationPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Perform validation of the given bean.
 * @param bean the bean instance to validate
 * @see javax.validation.Validator#validate
 */
protected void doValidate(Object bean) {
	Assert.state(this.validator != null, "No Validator set");
	Object objectToValidate = AopProxyUtils.getSingletonTarget(bean);
	if (objectToValidate == null) {
		objectToValidate = bean;
	}
	Set<ConstraintViolation<Object>> result = this.validator.validate(objectToValidate);

	if (!result.isEmpty()) {
		StringBuilder sb = new StringBuilder("Bean state is invalid: ");
		for (Iterator<ConstraintViolation<Object>> it = result.iterator(); it.hasNext();) {
			ConstraintViolation<Object> violation = it.next();
			sb.append(violation.getPropertyPath()).append(" - ").append(violation.getMessage());
			if (it.hasNext()) {
				sb.append("; ");
			}
		}
		throw new BeanInitializationException(sb.toString());
	}
}
 
Example #2
Source File: PropertyOverrideConfigurer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
		throws BeansException {

	for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) {
		String key = (String) names.nextElement();
		try {
			processKey(beanFactory, key, props.getProperty(key));
		}
		catch (BeansException ex) {
			String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
			if (!this.ignoreInvalidKeys) {
				throw new BeanInitializationException(msg, ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug(msg, ex);
			}
		}
	}
}
 
Example #3
Source File: MyShiroFilterFactoryBean.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Override
protected AbstractShiroFilter createInstance() throws Exception {
	SecurityManager securityManager = getSecurityManager();
	if (securityManager == null){
		throw new BeanInitializationException("SecurityManager property must be set.");
	}

	if (!(securityManager instanceof WebSecurityManager)){
		throw new BeanInitializationException("The security manager does not implement the WebSecurityManager interface.");
	}

	PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
	FilterChainManager chainManager = createFilterChainManager();
	chainResolver.setFilterChainManager(chainManager);
	return new MySpringShiroFilter((WebSecurityManager)securityManager, chainResolver);
}
 
Example #4
Source File: FreeMarkerView.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #5
Source File: SimpleServletPostProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof Servlet) {
		ServletConfig config = this.servletConfig;
		if (config == null || !this.useSharedServletConfig) {
			config = new DelegatingServletConfig(beanName, this.servletContext);
		}
		try {
			((Servlet) bean).init(config);
		}
		catch (ServletException ex) {
			throw new BeanInitializationException("Servlet.init threw exception", ex);
		}
	}
	return bean;
}
 
Example #6
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #7
Source File: ViewResolverRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Register a script template view resolver with an empty default view name prefix and suffix.
 * <p><strong>Note</strong> that you must also configure script templating by
 * adding a {@link ScriptTemplateConfigurer} bean.
 * @since 5.0.4
 */
public UrlBasedViewResolverRegistration scriptTemplate() {
	if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
		throw new BeanInitializationException("In addition to a script template view resolver " +
				"there must also be a single ScriptTemplateConfig bean in this web application context " +
				"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
				"This bean may be given any name.");
	}
	ScriptRegistration registration = new ScriptRegistration();
	UrlBasedViewResolver resolver = registration.getViewResolver();
	if (this.applicationContext != null) {
		resolver.setApplicationContext(this.applicationContext);
	}
	this.viewResolvers.add(resolver);
	return registration;
}
 
Example #8
Source File: RequiredAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<String>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example #9
Source File: JmsListenerEndpointRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Create and start a new container using the specified factory.
 */
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint,
		JmsListenerContainerFactory<?> factory) {

	MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);

	if (listenerContainer instanceof InitializingBean) {
		try {
			((InitializingBean) listenerContainer).afterPropertiesSet();
		}
		catch (Exception ex) {
			throw new BeanInitializationException("Failed to initialize message listener container", ex);
		}
	}

	int containerPhase = listenerContainer.getPhase();
	if (containerPhase < Integer.MAX_VALUE) {  // a custom phase value
		if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
			throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " +
					this.phase + " vs " + containerPhase);
		}
		this.phase = listenerContainer.getPhase();
	}

	return listenerContainer;
}
 
Example #10
Source File: PropertyOverrideConfigurer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * Process the given key as 'beanName.property' entry.
 */
protected void processKey(ConfigurableListableBeanFactory factory, String key, String value)
		throws BeansException {

	int separatorIndex = key.indexOf(this.beanNameSeparator);
	if (separatorIndex == -1) {
		throw new BeanInitializationException("Invalid key '" + key +
				"': expected 'beanName" + this.beanNameSeparator + "property'");
	}
	String beanName = key.substring(0, separatorIndex);
	String beanProperty = key.substring(separatorIndex+1);
	this.beanNames.add(beanName);
	applyPropertyValue(factory, beanName, beanProperty, value);
	if (logger.isDebugEnabled()) {
		logger.debug("Property '" + key + "' set to value [" + value + "]");
	}
}
 
Example #11
Source File: SimpleServletPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof Servlet) {
		ServletConfig config = this.servletConfig;
		if (config == null || !this.useSharedServletConfig) {
			config = new DelegatingServletConfig(beanName, this.servletContext);
		}
		try {
			((Servlet) bean).init(config);
		}
		catch (ServletException ex) {
			throw new BeanInitializationException("Servlet.init threw exception", ex);
		}
	}
	return bean;
}
 
Example #12
Source File: ViewResolverRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Register a {@code FreeMarkerViewResolver} with a ".ftl" suffix.
 * <p><strong>Note</strong> that you must also configure FreeMarker by
 * adding a {@link FreeMarkerConfigurer} bean.
 */
public UrlBasedViewResolverRegistration freeMarker() {
	if (!checkBeanOfType(FreeMarkerConfigurer.class)) {
		throw new BeanInitializationException("In addition to a FreeMarker view resolver " +
				"there must also be a single FreeMarkerConfig bean in this web application context " +
				"(or its parent): FreeMarkerConfigurer is the usual implementation. " +
				"This bean may be given any name.");
	}
	FreeMarkerRegistration registration = new FreeMarkerRegistration();
	UrlBasedViewResolver resolver = registration.getViewResolver();
	if (this.applicationContext != null) {
		resolver.setApplicationContext(this.applicationContext);
	}
	this.viewResolvers.add(resolver);
	return registration;
}
 
Example #13
Source File: RequiredAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example #14
Source File: PropertyResourceConfigurer.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * {@linkplain #mergeProperties Merge}, {@linkplain #convertProperties convert} and
 * {@linkplain #processProperties process} properties against the given bean factory.
 * @throws BeanInitializationException if any properties cannot be loaded
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	try {
		Properties mergedProps = mergeProperties();

		// Convert the merged properties, if necessary.
		convertProperties(mergedProps);

		// Let the subclass process the properties.
		processProperties(beanFactory, mergedProps);
	}
	catch (IOException ex) {
		throw new BeanInitializationException("Could not load properties", ex);
	}
}
 
Example #15
Source File: PropertyOverrideConfigurer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
		throws BeansException {

	for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) {
		String key = (String) names.nextElement();
		try {
			processKey(beanFactory, key, props.getProperty(key));
		}
		catch (BeansException ex) {
			String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
			if (!this.ignoreInvalidKeys) {
				throw new BeanInitializationException(msg, ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug(msg, ex);
			}
		}
	}
}
 
Example #16
Source File: PropertyOverrideConfigurer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Process the given key as 'beanName.property' entry.
 */
protected void processKey(ConfigurableListableBeanFactory factory, String key, String value)
		throws BeansException {

	int separatorIndex = key.indexOf(this.beanNameSeparator);
	if (separatorIndex == -1) {
		throw new BeanInitializationException("Invalid key '" + key +
				"': expected 'beanName" + this.beanNameSeparator + "property'");
	}
	String beanName = key.substring(0, separatorIndex);
	String beanProperty = key.substring(separatorIndex + 1);
	this.beanNames.add(beanName);
	applyPropertyValue(factory, beanName, beanProperty, value);
	if (logger.isDebugEnabled()) {
		logger.debug("Property '" + key + "' set to value [" + value + "]");
	}
}
 
Example #17
Source File: HttpServletProtocolSpringAdapter.java    From spring-boot-protocol with Apache License 2.0 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if(beanFactory.containsBean(beanName) && beanFactory.isSingleton(beanName)) {
        application.addSingletonBeanDefinition(bean, beanName, false);
    }
    if(bean instanceof AbstractServletWebServerFactory && ((AbstractServletWebServerFactory) bean).getPort() > 0){
        try {
            configurableServletContext((AbstractServletWebServerFactory) bean);
        } catch (Exception e) {
            BeanInitializationException exception = new BeanInitializationException(e.getMessage(),e);
            exception.setStackTrace(e.getStackTrace());
            throw exception;
        }
    }
    return bean;
}
 
Example #18
Source File: ViewResolverRegistry.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Register a script template view resolver with an empty default view name prefix and suffix.
 * <p><strong>Note</strong> that you must also configure script templating by
 * adding a {@link ScriptTemplateConfigurer} bean.
 * @since 5.0.4
 */
public UrlBasedViewResolverRegistration scriptTemplate() {
	if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
		throw new BeanInitializationException("In addition to a script template view resolver " +
				"there must also be a single ScriptTemplateConfig bean in this web application context " +
				"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
				"This bean may be given any name.");
	}
	ScriptRegistration registration = new ScriptRegistration();
	UrlBasedViewResolver resolver = registration.getViewResolver();
	if (this.applicationContext != null) {
		resolver.setApplicationContext(this.applicationContext);
	}
	this.viewResolvers.add(resolver);
	return registration;
}
 
Example #19
Source File: RestShiroFilterFactoryBean.java    From bootshiro with MIT License 6 votes vote down vote up
@Override
protected AbstractShiroFilter createInstance() throws Exception {
    LOGGER.debug("Creating Shiro Filter instance.");
    SecurityManager securityManager = this.getSecurityManager();
    String msg;
    if (securityManager == null) {
        msg = "SecurityManager property must be set.";
        throw new BeanInitializationException(msg);
    } else if (!(securityManager instanceof WebSecurityManager)) {
        msg = "The security manager does not implement the WebSecurityManager interface.";
        throw new BeanInitializationException(msg);
    } else {
        FilterChainManager manager = this.createFilterChainManager();
        RestPathMatchingFilterChainResolver chainResolver = new RestPathMatchingFilterChainResolver();
        chainResolver.setFilterChainManager(manager);
        return new RestShiroFilterFactoryBean.SpringShiroFilter((WebSecurityManager)securityManager, chainResolver);
    }
}
 
Example #20
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #21
Source File: SimpleServletPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof Servlet) {
		ServletConfig config = this.servletConfig;
		if (config == null || !this.useSharedServletConfig) {
			config = new DelegatingServletConfig(beanName, this.servletContext);
		}
		try {
			((Servlet) bean).init(config);
		}
		catch (ServletException ex) {
			throw new BeanInitializationException("Servlet.init threw exception", ex);
		}
	}
	return bean;
}
 
Example #22
Source File: PropertyOverrideConfigurer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Process the given key as 'beanName.property' entry.
 */
protected void processKey(ConfigurableListableBeanFactory factory, String key, String value)
		throws BeansException {

	int separatorIndex = key.indexOf(this.beanNameSeparator);
	if (separatorIndex == -1) {
		throw new BeanInitializationException("Invalid key '" + key +
				"': expected 'beanName" + this.beanNameSeparator + "property'");
	}
	String beanName = key.substring(0, separatorIndex);
	String beanProperty = key.substring(separatorIndex+1);
	this.beanNames.add(beanName);
	applyPropertyValue(factory, beanName, beanProperty, value);
	if (logger.isDebugEnabled()) {
		logger.debug("Property '" + key + "' set to value [" + value + "]");
	}
}
 
Example #23
Source File: RpcExporterRegister.java    From brpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                    BeanDefinitionRegistry registry) {
    Map<Class, String> serviceExporterMap = new HashMap<>();
    AnnotationBeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator();
    Collection<BeanDefinition> candidates = getCandidates(resourceLoader);
    for (BeanDefinition candidate : candidates) {
        Class<?> clazz = getClass(candidate.getBeanClassName());
        Class<?>[] interfaces = ClassUtils.getAllInterfacesForClass(clazz);
        if (interfaces.length != 1) {
            throw new BeanInitializationException("bean interface num must equal 1, " + clazz.getName());
        }
        String serviceBeanName = beanNameGenerator.generateBeanName(candidate, registry);
        String old = serviceExporterMap.putIfAbsent(interfaces[0], serviceBeanName);
        if (old != null) {
            throw new RuntimeException("interface already be exported by bean name:" + old);
        }
        registry.registerBeanDefinition(serviceBeanName, candidate);
    }
}
 
Example #24
Source File: RequiredAnnotationBeanPostProcessor.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
		throws BeansException {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<String>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}
 
Example #25
Source File: RpcDefinitionPostProcessor.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
/**
 * 添加配置者
 *
 * @param config   配置
 * @param prefix   前缀
 * @param counters 计数器
 * @param configs  配置容器
 */
protected <T extends AbstractInterfaceConfig> void addConfig(final T config,
                                                             final String prefix,
                                                             final Map<String, AtomicInteger> counters,
                                                             final Map<String, T> configs) {
    if (config == null) {
        return;
    }
    String name = computeName(config, prefix, counters);
    if (!isEmpty(name)) {
        if (configs.putIfAbsent(name, config) != null) {
            //名称冲突
            throw new BeanInitializationException("duplication bean name " + name);
        }
    }
}
 
Example #26
Source File: PropertyOverrideConfigurer.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Process the given key as 'beanName.property' entry.
 */
protected void processKey(ConfigurableListableBeanFactory factory, String key, String value)
		throws BeansException {

	int separatorIndex = key.indexOf(this.beanNameSeparator);
	if (separatorIndex == -1) {
		throw new BeanInitializationException("Invalid key '" + key +
				"': expected 'beanName" + this.beanNameSeparator + "property'");
	}
	String beanName = key.substring(0, separatorIndex);
	String beanProperty = key.substring(separatorIndex + 1);
	this.beanNames.add(beanName);
	applyPropertyValue(factory, beanName, beanProperty, value);
	if (logger.isDebugEnabled()) {
		logger.debug("Property '" + key + "' set to value [" + value + "]");
	}
}
 
Example #27
Source File: PropertyOverrideConfigurer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
		throws BeansException {

	for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) {
		String key = (String) names.nextElement();
		try {
			processKey(beanFactory, key, props.getProperty(key));
		}
		catch (BeansException ex) {
			String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
			if (!this.ignoreInvalidKeys) {
				throw new BeanInitializationException(msg, ex);
			}
			if (logger.isDebugEnabled()) {
				logger.debug(msg, ex);
			}
		}
	}
}
 
Example #28
Source File: JmsListenerEndpointRegistry.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create and start a new container using the specified factory.
 */
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint,
		JmsListenerContainerFactory<?> factory) {

	MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);

	if (listenerContainer instanceof InitializingBean) {
		try {
			((InitializingBean) listenerContainer).afterPropertiesSet();
		}
		catch (Exception ex) {
			throw new BeanInitializationException("Failed to initialize message listener container", ex);
		}
	}

	int containerPhase = listenerContainer.getPhase();
	if (containerPhase < Integer.MAX_VALUE) {  // a custom phase value
		if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
			throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " +
					this.phase + " vs " + containerPhase);
		}
		this.phase = listenerContainer.getPhase();
	}

	return listenerContainer;
}
 
Example #29
Source File: PropertyResourceConfigurer.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * {@linkplain #mergeProperties Merge}, {@linkplain #convertProperties convert} and
 * {@linkplain #processProperties process} properties against the given bean factory.
 * @throws BeanInitializationException if any properties cannot be loaded
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	try {
		Properties mergedProps = mergeProperties();

		// Convert the merged properties, if necessary.
		convertProperties(mergedProps);

		// Let the subclass process the properties.
		processProperties(beanFactory, mergedProps);
	}
	catch (IOException ex) {
		throw new BeanInitializationException("Could not load properties", ex);
	}
}
 
Example #30
Source File: RequiredAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {

	if (!this.validatedBeanNames.contains(beanName)) {
		if (!shouldSkip(this.beanFactory, beanName)) {
			List<String> invalidProperties = new ArrayList<>();
			for (PropertyDescriptor pd : pds) {
				if (isRequiredProperty(pd) && !pvs.contains(pd.getName())) {
					invalidProperties.add(pd.getName());
				}
			}
			if (!invalidProperties.isEmpty()) {
				throw new BeanInitializationException(buildExceptionMessage(invalidProperties, beanName));
			}
		}
		this.validatedBeanNames.add(beanName);
	}
	return pvs;
}