Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring specify the correct bean references as factory method arguments

Tags:

spring-mvc

How can specify the correct bean refrences, When I using Abstrarct factory method pattern with Spring.

I get constructor arguments errors on the Spring dispatcher-servlet.xml.

the errors:

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

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

like image 648
mkohan Avatar asked Oct 14 '22 17:10

mkohan


1 Answers

If your findCategory factory takes a given enum, then Spring does it all for you.

e.g

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

now in Spring

<constructor-arg value="A" />
like image 173
harschware Avatar answered Oct 18 '22 02:10

harschware