简体   繁体   中英

Spring Boot Project throwing "At least 1 bean exception"

I'm not able to run my project. Getting NoBeanFoundException repeatedly.The exception is: No qualifying bean of type 'com.example.Model.Movie' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} The link for the repo is https://github.com/RaviShekhawat/BMSBackend

Your Movie class isn't a spring bean, so you won't be able to @Autowire it into the MovieController.

As your Movie is an @Entity it doesn't make sense to have it as a spring bean. Spring beans are usually singletons that have no state and hang around for the life of the application. Your movie does have state, and I assume should only hang around for individual requests.

I'm not sure what you're trying to do with the Movie movie field in the MovieController. But you don't really want to have it as a field. Most of the methods in your controller work how I'd expect in that they retrieve data from the database and return it to the caller, or take data from the caller and pass it to the database.

The first method...

    @Autowired
    Movie movie;

    @RequestMapping(value="/GetReactions", method= RequestMethod.GET)
    public Integer getReactions() {

       return movie.getNo_of_reviews();

    }

Looks like you're trying to save some state in the controller between calls. Don't do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM