Boa noite, estou fazendo o exercicio 13.5 Web da Caelum.
Faço todo o procedimento. Porém, dá erro já no console do Tomcat, segue erro:
Error creating bean with name ‘tarefasController’ defined in file [C:\Users\JEEF\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\fj21-tarefas\WEB-INF\classes\br\com\caelum\tarefas\controller\TarefasController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [br.com.caelum.tarefas.dao.JdbcTarefaDao]: …
Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name ‘dataSource’ defined in ServletContext resource [/WEB-INF/spring-context.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
atorg.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)
Segue o XML :
< bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
< property name="driverClassName" value="com.mysql.jdbc.Driver"/>
< property name="url" value="jdbc:mysql://localhost/fj21"/>
< property name="username" value="root"/>
< property name="password" value="yusuke"/>
< /bean>
Segue o Dao:
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import br.com.caelum.tarefas.ConnectionFactory;
import br.com.caelum.tarefas.modelo.Tarefa;
@Repository
public class JdbcTarefaDao {
private final Connection connection;
@Autowired
public JdbcTarefaDao(DataSource dataSource) {
try{
this.connection = dataSource.getConnection();
}catch (SQLException e){
throw new RuntimeException(e);
}
}
Segue o Controller:
@Controller
public class TarefasController {
private final JdbcTarefaDao dao;
@Autowired
public TarefasController(JdbcTarefaDao dao) {
this.dao = dao;
}
Eu vi um tópico com o mesmo problema aqui no GUJ, porém algumas mensagens não aparecem os codigos que o pessoal tentou e conseguiu resolver, ai fiquei meio perdido.
Poderiam me ajudar por favor?