2
I am running my spring boot project with mysql connection and is giving the following failure:
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.
Man 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);
}
Man 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";
}
}
mine 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?
It seems that the problem may be the Event entity. Are you sure that the @Event Id is a String?
– touchmx
It is not locating the repository, which has to do with the entity Event?
– Airton Lira jr
The class with the main method is in which package? com.eventoapp?
– StatelessDev
Is using the Starter of date,
spring-boot-starter-data-jpa
? If not, write down yourDataConfiguration
with@EnableJpaRepositories
.– Bruno César
How is your entity
Evento
? She is marked with@Entity
? Post her code too.– Dherik