Field in required a bean of type that could not be found consider defining a bean of type in your configuration

Alon :

I'm getting the following error when trying to run my app:

Field edao in com.alon.service.EmployeeServiceImpl required a bean of type 'com.alon.repository.EmployeeRepository' that could not be found.

The injection point has the following annotations:

  • @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'com.alon.repository.EmployeeRepository' in your configuration.

Project structure:

enter image description here

EmployeeRepository:

package com.alon.repository;

import com.alon.model.Employee;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface EmployeeRepository {
    List<Employee> findByDesignation(String designation);
    void saveAll(List<Employee> employees);
    Iterable<Employee> findAll();
}

EmployeeServiceImpl:

package com.alon.service;

import com.alon.model.Employee;
import com.alon.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeRepository edao;

    @Override
    public void saveEmployee(List<Employee> employees) {
        edao.saveAll(employees);
    }

    @Override
    public Iterable<Employee> findAllEmployees() {
        return edao.findAll();
    }

    @Override
    public List<Employee> findByDesignation(String designation) {
        return edao.findByDesignation(designation);
    }
}

MyApplication:

package com.alon;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyApplicataion {
    public static void main(String[] args) {
        SpringApplication.run(MyApplicataion.class, args);
    }
}
ali4j :

As you have added spring-boot tag I guess you are using sprig data jpa. Your repository interfaces should extend org.springframework.data.repository.Repository (a marker interface) or one of its sub interfaces (usually org.springframework.data.repository.CrudRepository) for instructing spring to provide a runtime implementation of your repository, if any of those interfaces are not extened you'll get

bean of type 'com.alon.repository.EmployeeRepository' that could not be found.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Consider defining a bean of type 'io.ipl.amaresh.data.JobCompletionNotificationListener' in your configuration. The bean could not be found in that

Consider defining a bean of type * in your configuration

Consider defining a bean of type in your configuration

Consider defining a bean of type 'UserConverter' in your configuration

Consider defining a bean of type 'package' in your configuration [Spring-Boot]

Consider defining a bean of type 'service' in your configuration [Spring boot]

Consider defining a bean of type 'javax.servlet.ServletContext' in your configuration

APPLICATION FAILED TO START - Consider defining a bean of type in your configuration [SpringBoot]

Consider defining a bean of type 'org.modelmapper.ModelMapper' in your configuration

Consider defining a bean of type 'int' in your configuration[SpringBoot]

Field required a bean of type ... that could not be found

Field personRepositary in () required a bean of type () that could not be found

Field memberRepo in (...) required a bean of type that could not be found

Spring Boot - Injecting Repository into Controller throws Consider defining a bean of type 'Type' in your configuration

Spring boot Field required a bean of type that could not be found

Field ordonnanceService in ...OrdonnanceController required a bean of type 'OrdonnanceService' that could not be found

Field itemRepository in HomePageController required a bean of type ItemRepository that could not be found

Field Repository in Controller required a bean of type Repository that could not be found

Consider revisiting the entries above or defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration

SpringBootTest - Consider defining a bean of type 'java.lang.String' in your configuration

Consider defining a bean of type '[3rd party dependency]' in your configuration

Consider defining a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' in your configuration

Consider defining a bean of type 'com.ensat.services.ProductService' in your configuration

Consider defining a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' in your configuration

only after refactoring packages names, Consider defining a bean of type * in your configuration

Redis Issue Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' in your configuration

Consider defining a bean of type 'com.gisapp.gisapp.dao.IUserDAO' in your configuration

How do i resolve Consider defining a bean of type 'java.lang.String' in your configuration?