Na aula 2 fiz tudo corretamente porem quando vamos fazer a injeção do repository da esse erro : Error creating bean with name 'convidadoController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.alura.listavip.repository.ConvidadoRepository br.com.alura.listavip.conf.ConvidadoController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.alura.listavip.repository.ConvidadoRepository] 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)}
aqui esta o codigo:
package br.com.alura.listavip.conf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import br.com.alura.listavip.model.Convidado;
import br.com.alura.listavip.repository.ConvidadoRepository;
@Controller
public class ConvidadoController {
@Autowired
private ConvidadoRepository repository;
@RequestMapping("/")
public String index(){
return "index";
}
@RequestMapping("listaconvidados")
public String listaConvidados(Model model){
Iterable<Convidado> convidados = repository.findAll();
model.addAttribute("convidados", convidados);
return "lista";
}
}
package br.com.alura.listavip.conf;
import javax.sql.DataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
@SpringBootApplication
public class Configuracao {
public static void main(String[] args) {
SpringApplication.run(Configuracao.class, args);
}
@Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/listavip");
dataSource.setUsername("root");
dataSource.setPassword("mysql");
return dataSource;
}
}
package br.com.alura.listavip.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Convidado {
@Id
@GeneratedValue
private Integer id;
private String nome;
private String email;
private String telefone;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
}
package br.com.alura.listavip.repository;
import org.springframework.data.repository.CrudRepository;
import br.com.alura.listavip.model.Convidado;
public interface ConvidadoRepository extends CrudRepository<Convidado, Long>{
}