aratata
aratata

Reputation: 1397

How should i fix required a bean of type that could not be found?

I keep on getting an error: "required a bean that could not be found." And i really can't figure out why anymore.

I saw that many had the same issue as me before but none of the given answers work for me. Tried rearranging packages, adding @ComponentScan to the application but nothing helped.

Part of my controller:

@RestController
@RequestMapping("/api")
public class JavarskiKontroler {

@Autowired
private JavarService javarService;

@RequestMapping("/javari")
public List<Javar> getAllJavars() {
    return javarService.getAllJavars();
}

@PostMapping("/javar")
public Javar createJavar(@Valid @RequestBody Javar note) {
    return javarService.createJavara(note);
}

Part of my service implementation (JavarService):

@Service
public class JavarService {


@Autowired
private Javarer javarica;

public List<Javar> getAllJavars() {

    return javarica.findAll();
}

public Javar createJavara(Javar note) {

    return javarica.save(note);
}

My service(Javarer):

@Repository
public interface Javarer extends JpaRepository<Javar, Integer> {
}

And the error that I keep on getting:

Description:

 Field javarService in controller.JavarskiKontroler required a bean of type 'serviceImpl.JavarService' 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 'serviceImpl.JavarService' in your configuration.

project structure:

It would be great if someone could at least point me to where I should look for the solution next, thanks anyway.

Upvotes: 1

Views: 956

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 39978

Your packages are unstructured, use @CompnentScan including packages names on Main class

@ComponentScan(basePackages = {"controller", "domain", "exception", "service" })

Upvotes: 1

Related Questions