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
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)
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.
Oi Edjane, não, não estou usando JPA não.
Dei uma olhada nesse outro erro: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource’
Não esta achando a classe com o nome dataSource, mas tbm não consegui resolver.
Eu fiz esse curso na Caelum SP, mas já faz tanto tempo e trabalhando com outras coisas já não lembro muita coisa. Mas esse erro diz muito: 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] posta o código completo da classe TarefasController, pode ficar mais fácil de eu ou outra pessoa ajudar!
Só mais uma coisa você esta usando Maven? Se sim, verifica se não esta faltando alguma dependência!