Question: I am using Spring Boot 2.0.0.RC1 (It include Spring Framework 5.0.3.RELEASE), Hibernate 5.2.12.Final, JPA 2.1 API 1.0.0.Final .

I have a class

```
package com.example;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManagerFactory;

@Configuration
public class BeanConfig {

    @Autowired
    EntityManagerFactory emf;

    @Bean
    public SessionFactory sessionFactory(@Qualifier("entityManagerFactory") EntityManagerFactory emf) {
        return emf.unwrap(SessionFactory.class);
    }

}

```

Then error

```
Error
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method sessionFactory in com.example.BeanConfig required a bean of type 'javax.persistence.EntityManagerFactory' that could not be found.

Action:

Consider defining a bean of type 'javax.persistence.EntityManagerFactory' in your configuration.

Process finished with exit code 1

```

How to fix this?

Answer: 
In `BeanConfig`, you should inject the JPA `EntityManager` via `@PersistenceUnit`, not `@Autowired`.

And remove the `getSessionFactory` since the Hibernate SessionFactory is already created internally and you can always unwrap the `EntityManagerFactory`.

Like this:

```
@Configuration
public class BeanConfig {

    @PersistenceUnit
    EntityManagerFactory emf;

}

```
The specific error you are having is caused by the `@Qualifier` annotation; Spring is looking for a Bean with the specific name you mentioned, instead of looking for any Bean of type `EntityManagerFactory`. Just remove the annotation.

However, once you fix that, and because you are also injecting the Bean in the method that constructs SessionFactory, Spring Boot will generate another error related to cyclic dependencies. To avoid that, just remove the parameter altogether from `sessionFactory` method, since you already injected `EntityManagerFactory` in your Config class.

This code will work :

```
@Bean
public SessionFactory sessionFactory() {
        return emf.unwrap(SessionFactory.class);
}

```