Hello. Tell me how to implement such a functional: for a bean there are 2 implementation classes: class1, class2, one of these classes is selected in the config, and the output I want to get an array of these beans. That is, roughly speaking, the definition in the config for one bean, and in runtime in the program I want such bins to be an array. Can this be done using Spring tools? Thank.
1 answer
Once finished training. It was possible to choose how to pull data from the database. Using pure JDBC or Hibernate. Wrote a class that is configured in xml and then runtime using it to create the desired class. Approximate class code:
public class CarDaoFactory { private CarDao dao; private PersistanceType persistanceType; public PersistanceType getPersistanceType() { return persistanceType; } public void setPersistanceType(PersistanceType persistanceType) { this.persistanceType = persistanceType; } public CarDao getCarDao() throws DataLayerException { switch (persistanceType) { case JDBC : dao = JDBCCarDao.getInstance(); break; case Hibernate : dao = HibernateCarDao.getInstance(); break; } return dao; } } public enum PersistanceType { JDBC,Hibernate }
-
<bean id="carDaoFactory" class="com.epam.dao.factory.CarDaoFactory" scope="singleton"> <property name="persistanceType"> <value>JDBC</value> </property> </bean>
- Thanks, and did - Vladimir
|