This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

However, if the property myIntrfc is set to autowired, Spring complains "no matching bean of type MyIntrfc". I guess it is due to the order: autowiring is done before post-construct of the depends-on bean. Am I correct and any way to change the order?

Creating bean definitions should be done before this so instead of a factorybean I suggest using a BeanFactoryPostProcessor that also makes your proxies/bean definitions registered like all the other and you don't have these issues.

It BTW has nothing to do with ordering but the fact that you are probably wrongly using the FactoryBean, it probably doesn't return the correct type so spring doesn't know that your factory bean is creating instances of class X.

Comment

Thanks Marten. My factory is actually not a FactoryBean. FactoryBean makes a bean of a known type. My factory makes multiple beans of types (specified by List of java.lang.Class) that are unknown at compile time.

BeanFactoryPostProcessor is surely more appropriate than ApplicationContextAware + @PostConstruct. But it still doesn't work after rewrite. My factory makes JDK proxy:

When the proxy is injected explicity (ref="myProxy"), the factory method (getProxy) is invoked. For autowiring, it is not invoked before Spring complains "no matching bean of type ...". I guess it is necessary to specify in the bean definition that the proxy is an instance of the desired interface, but I can't find the API to do so.