Spring specify the correct bean references as arguments to the factory method

How to specify the correct bean reflexes when I use the Abstrarct factory method template with Spring.

I get constructor argument errors on Spring dispatcher-servlet.xml.

errors:

Ambiguous argument types of the factory method - did you specify the correct bean references as arguments to the factory method?

short dispatcher-servlet.xml

<bean id="myFactory" class="cwsei.spring.dao.CategoryFactory" factory-method="findCategory">
<constructor-arg type="java.lang.Enum" value="${categoryType}" />
</bean>

Here is my code:

public abstract class Category {
public abstract List list(int departId);
..
}
public class CategoryFactory {

public enum CategoryType { firstclass,secondClass,...}

public static Category findCategory(CategoryType categoryType) {
...
}
}

Thanks mkohan

+5
source share
2 answers

If your findCategory factory accepts the given enumeration, then Spring does everything for you.

eg

public class enum X { A, B }
public CategoryFactory findCategory( X someX ) 

now in spring

<constructor-arg value="A" />
+3
source
  • Lazy initialize bean if possible
  • factory - - bean,

    <constructor-arg><null/></constructor-arg> 
    

+1

All Articles