最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Spring Boot - ClassLoader for Same Name Entity - Stack Overflow

programmeradmin9浏览0评论

I am trying to create a structure to allow customization in my spring boot project. When there are two Entities with the same name, I want the Entities in the specified package to crush the entity in the other package. How can I do this? I couldn't do it with ClassLoader because spring boot scans Entities with @EntityScan.

Main class

@SpringBootApplication
@EnableJpaRepositories(basePackages = "com.project")
@EntityScan(basePackages = {"com.project"})
public class ProjectMain {
    SpringApplication.run(ProjectMain.class, args);
}

Entity in com.project.data.entity package

package com.project.data.entity;

import jakarta.persistence.Entity;

@Entity
public class User {
   ...
}

Entity in com.project.data.domain package

package com.project.data.domain;

import jakarta.persistence.Entity;

@Entity
public class User {
   ...
}

I cannot solve the problem with ClassLoader because Spring Boot manages Entities differently. I get the following error when there is an Entity with the same name. As I said, my goal is to ignore more than one entity with the same name.

Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Entity classes [com.project.data.entity.User] and [com.project.data.domain.User] share the entity name 'User' (entity names must be distinct)
发布评论

评论列表(0)

  1. 暂无评论