Skip to content

EntityManager Bean can not be autowired in Spring Boot 3 #33492

@fabian-froehlich

Description

@fabian-froehlich

Previously in Spring 2.7 we could inject a EntityManager Bean into a Service via Constructor

@Service
public class MyService {
    
    private final EntityManager entityManager;

    public MyService(EntityManager entityManager){
        this.entityManager = entityManager;
    }
}

In Spring-Boot this is not possible anymore.
IntelliJ shows in Spring Boot 2.7, that the EntityManager Bean is injected from JpaBaseConfiguration's factory Method entityManagerFactory that returns a LocalContainerEntityManagerFactoryBean.

An alternative could be the @PersistenceContext annotation. But since I like to get the implementation from application context rather than container context, I would prefer the previous behavior.

Since I did not found anything in the migration guide or on the web I raise this issue here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions