spring - injeção de dependencia

15/02/2016

4

ao criar o primeiro exemplo do curso de JdbcTemplate - Spring 4, estou recebendo o seguinte erro:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'editoraDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate br.com.devmedia.editora.entity.dao.EditoraDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

ja tentei de tudo, mas nao consigo....


@Repository
public class EditoraDao {

@Autowired
private JdbcTemplate jdbcTemplate;

public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}



}

package br.com.devmedia.editora;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

import br.com.devmedia.editora.entity.dao.EditoraDao;

/**
* Hello world!
*
*/
@EnableAutoConfiguration
@ComponentScan
public class AppEditora implements CommandLineRunner
{
@Autowired
private EditoraDao editoraDao;

public static void main( String[] args )
{

SpringApplication sp = new SpringApplication();
sp.run(AppEditora.class);

}

public void run(String... arg0) throws Exception {
// TODO Auto-generated method stub

editoraDao.getJdbcTemplate();
System.out.println( "Hello World!" );
}


}
Responder