Без Spring я инициализировал объект так:
DAOFactory factory = new MySqlDaoFactory
StudentDao studentDao = factory.getStudentDAO(connection)
Как мне это правильно прописать в bean, передать на вход методу getStudentDAO connection ? Я писал так, но выскакивает ошибка:
<bean id="MySqlDaoFactory" class="mysql.MySqlDaoFactory">
</bean>
<bean id="DaoFactory" class="dao.DaoFactory">
</bean>
<bean id="Connection" class="mysql.MySqlDaoFactory"
factory-bean="MySqlDaoFactory" factory-method="getConnection">
</bean>
<bean id="studentDao" class="mysql.MySqlStudentDao"
factory-bean="MySqlDaoFactory" factory-method="getStudentDAO" constructor-arg="Connection">
</bean>
класс DAOFactory и StudentDao абстрактные
класс MySqlDaoFactory:
public class MySqlDaoFactory extends DAOFactory{
private Connection connection = null;
public Connection getConnection() throws DAOException {
Properties prop = new Properties();
try {
...
} catch (Exception e) {
throw new DAOException("Error of connection", e);
}
return connection;
}
public StudentDao getStudentDAO(Connection connection){
return new MySqlStudentDao(connection);
}
MysqlStudentDao наследует абстрактный StudentDao и прописывает все CRUD