Skip to content

BeanFactoryPostProcessor not working for @Value [SPR-8213] #12863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Apr 6, 2011 · 3 comments
Closed
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 6, 2011

Yanming Zhou opened SPR-8213 and commented

I have the same problem with http://forum.springsource.org/showthread.php?t=105476


Affects: 3.0.5

Reference URL: http://forum.springsource.org/showthread.php?t=105476

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 12, 2011

Chris Beams commented

I've taken a look at the form post and reviewed #11277, but it's still not exactly clear to me what the issue is that you are having particularly. Could you please provide more detail, code snippets, etc? Thanks.

@spring-projects-issues
Copy link
Collaborator Author

Yanming Zhou commented

package org.ironrhino.core.remoting;

import javax.inject.Named;
import javax.inject.Singleton;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

@Named
@Singleton
public class Test implements BeanFactoryPostProcessor {

@Value("${test.value}")
String value;

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory clbf)
		throws BeansException {
}

}

cannot inject test.value from properties file

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 12, 2011

Chris Beams commented

This is actually a fundamental limitation of @Autowired and @Value (and @Inject and @Resource and @Required for that matter) - because they are themselves processed by BeanPostProcessors, they may not be used within BeanPostProcessor or BeanFactoryPostProcessor types. The latter is what you're attempting to do, and unfortunately it just won't work.

If your B(F)PPs require value or dependency injection, you'll need to wire them up via XML, or altertatively within a @Bean method. Do make sure to mark the @Bean method static if you go that route (see resolution comments on #12917)

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

1 participant