Ao tentar pegar os dados do banco ocorre o seguinte erro:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-25 15:23:58.881 ERROR 6568 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field repositorio in br.com.desafio.controllers.UsuarioController required a bean of type 'br.com.desafio.repositorio.UsuarioRepositorio' that could not be found.
Action:
Consider defining a bean of type 'br.com.desafio.repositorio.UsuarioRepositorio' in your configuration.
Essas são minhas classes e meu pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.desafio.acesso</groupId>
<artifactId>desafio</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.unbescape/unbescape -->
<dependency>
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
</dependencies>
</project>
package br.com.desafio.modelos;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity(name="gerenciador")
public class Gerenciador {
@Id
@GeneratedValue
private long id;
private String servico;
private String senha;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getServico() {
return servico;
}
public void setServico(String servico) {
this.servico = servico;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
package br.com.desafio.controllers;
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.desafio.modelos.Gerenciador; import br.com.desafio.repositorio.UsuarioRepositorio;
@Controller public class UsuarioController {
@Autowired private UsuarioRepositorio repositorio;
@RequestMapping("/") public String index() { return "index"; }
@RequestMapping("homeinicio") public String usuarioLogado(Model model) {
//Passa senhas para view Iterable lista = repositorio.findAll();
model.addAttribute("lista de senhas", lista);
return "usuariologado"; } }
package br.com.desafio.controllers;
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); }
//Conexao com o banco mysql @Bean public DataSource dataSource(){ DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/desafio_acesso"); dataSource.setUsername("root"); dataSource.setPassword("123456"); return dataSource; } }
``` Já encontrei em alguns fóruns pessoas com o mesmo problema mas nenhuma das respostas resolveu meu problema.