Announcement Announcement Module
Collapse
No announcement yet.
Database-backed configurations possible? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Database-backed configurations possible?

    The problem is thus:
    Typical Spring configurations (XML or otherwise) assume that we know at deploy/config time , what the dependency of one bean would be. But in our case we do not know the dependent class until runtime.

    I am wondering if we can do Database-backed configurations in a manner similar to PropertyPlaceHolderConfigurer - wherein certain property values are fed in by a field from a particular query instead of .properties file being the source.

    For eg consider a Payment Processing Service bean:

    <bean id="paymentProcessService" class="com.company.service.PaymentService">
    <property name="merchant"><value>${merchantClass}</value></property>
    </bean>

    Where "merchant" is an interface with implementation being "merchantClass", merchantClass could be any of
    1. VerisignPaymentService
    2. PayPalPaymentService
    3. ChaseBankPaymentService
    4. SwissBankPaymentService
    and so on...

    We have a case where "PaymentService" depends on a "merchant" interface and there are atleast 5 to 10 different implementations of that interface. Secondly we do not know until runtime(based on certain values retrieved from the DB and user request) which of the above particular implementation of "merchant" interface would be wired in.

    We have a home-grown Database-backed way of resolving it. Spring claims that it also has a Database-backed configuration mechanism, but I haven't been able to locate a solution. That is we find out the class from a DB table like this:

    "select merchantClass from Merchants where userID = 123"

    We would want the query result of the above query to be wired in the bean configuration.

    Your answer is greatly appreciated.
    Thanks.

  • #2
    You consider just call an setUp method like

    "PaymentService service = (PaymentService)appContext.getBean("paymentProcess Service");
    service.setMerchant( implementation class by business rules );"

    that u call at runtime when the correct implementation for merchant are required?

    I think it is just the correct way...

    Comment

    Working...
    X