I'm running my spring boot project with connection to mysql and it's giving the following crash:
Description:
Field er in com.eventoapp.controllers.EventoController required a bean of type 'com.eventoapp.repository.EventoRepository' that could not be found.
Action:
Consider defining a bean of type 'com.eventoapp.repository.EventoRepository' in your configuration.
My EventoReposity
:
package com.eventoapp.repository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.eventoapp.models.Evento;
@Repository
public interface EventoRepository extends CrudRepository<Evento, String>{
Evento findByCodigo(long codigo);
}
My EventoController
:
package com.eventoapp.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.eventoapp.models.Evento;
import com.eventoapp.repository.EventoRepository;
@Controller
public class EventoController {
@Autowired
EventoRepository er;
@RequestMapping(value="/cadastrarEvento", method=RequestMethod.GET)
public String form() {
return "evento/formEvento";
}
@RequestMapping(value="/cadastrarEvento", method=RequestMethod.POST)
public String form(Evento evento) {
er.save(evento);
return "redirect:/cadastrarEvento";
}
}
My DataConfiguration
:
package com.eventoapp.eventoapp;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
@Configuration
public class DataConfiguration {
@Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/eventosapp");
dataSource.setUsername("root");
dataSource.setPassword("hednf8iw");
return dataSource;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter(){
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.MYSQL);
adapter.setShowSql(true);
adapter.setGenerateDdl(true);
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
adapter.setPrepareConnection(true);
return adapter;
}
}
Any idea what it might be?