Ранее я часто использовал Mybatis , как показано ниже.
Код: Выделить всё
// I often declare mapper first, and inject it to my persistence.
@Mapper
public interface MyBatisMapper {/* ... */}
/* ------------ */
@Repository
public class MyBatisRepo {
private final MyBatisMapper mapper;
public MyBatisRepo(MyBatisMapper mapper) {
this.mapper = mapper;
}
/* ... */
}
< /code>
Итак, я попробовал jpa < /code> таким образом и столкнулся с круглой зависимостью.TestEntity
Код: Выделить всё
// entity just for test
@Entity
public class TestEntity {
@Id
private Long id;
}
< /code>
[list]
[*] Интерфейс хранилища (контракты) < /li>
< /ol>
// Persistence contracts
public interface TestRepo {
}
< /code>
JPA DAO
//
public interface JPATestRepo extends JpaRepository {
}
< /code>
Реализации реализации < /li>
< /ol>
@Repository
public class JPATestRepoImpl implements TestRepo {
private final JPATestRepo jpaRepo;
public JPATestRepoImpl(JPATestRepo jpaRepo) {
this.jpaRepo = jpaRepo;
}
}
< /code>
Ошибки < /li>
< /ol>
2024-10-19T19:46:00.760+09:00 WARN 66384 --- [testing] [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'JPATestRepoImpl' defined in file [/~~~/Desktop/Coding/testing/build/classes/java/main/core/testing/JPATestRepoImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'JPATestRepoImpl': Requested bean is currently in creation: Is there an unresolvable circular reference?
2024-10-19T19:46:00.761+09:00 INFO 66384 --- [testing] [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-10-19T19:46:00.762+09:00 INFO 66384 --- [testing] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2024-10-19T19:46:00.807+09:00 INFO 66384 --- [testing] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2024-10-19T19:46:00.811+09:00 INFO 66384 --- [testing] [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-10-19T19:46:00.825+09:00 ERROR 66384 --- [testing] [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
┌──->──┐
| JPATestRepoImpl defined in file [/~~~/Desktop/Coding/testing/build/classes/java/main/core/testing/JPATestRepoImpl.class]
└──
В консоли говорится, что jpatestrepoimpl < /code> имеет цикл для себя. < /p>
Но в jpatestrepoimpl < /code> на выше, это не так. (по крайней мере, по моей мысли) Magic ...
Кажется, что Spring или JPA конфликтует его имена бобов друг с другом, но я понятия не имею, почему она имеет. Если есть какая -либо политика от JPA, есть ли на ней какая -либо документация?>
Подробнее здесь: https://stackoverflow.com/questions/791 ... ementation