[SPRING] Sprint 부트 데이터 JPA : 'java.util.Set <javax.persistence.EntityManager>'유형의 유효한 bean이 없습니다.
SPRINGSprint 부트 데이터 JPA : 'java.util.Set '유형의 유효한 bean이 없습니다.
나는 spring-boot-startter-data-jpa로 시작할 수 없다. 나는이 가이드 다음에 간단한 Spring Boot app를 만들었지 만, Hibernate와 관련된 설정을 가지고있다.
build.gradle :
dependencies {
// Spring stuff
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.1.RELEASE'
compile 'org.springframework.data:spring-data-jpa'
compile 'org.springframework:spring-webmvc'
// Jackson
compile 'com.fasterxml.jackson.core:jackson-databind:+'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:+'
// Postgres
compile 'org.postgresql:postgresql:+'
// Hibernate
compile 'org.hibernate:hibernate-core:5.2.8.Final'
}
앱을 실행하려고 할 때마다 다음과 같이 끝납니다.
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-02-24 16:20:27.710 ERROR 1070 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jpaContext': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Set<javax.persistence.EntityManager>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
at nl.eonics.cdaas.service.Application.main(Application.java:14) [main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Set<javax.persistence.EntityManager>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
... 23 common frames omitted
나는이 버그 (1.10.7로보고 된 바에 따르면 고정되어 있음)를 보았지만 spring-data-jpa를 1.9.x로 다운 그레이드하는 것은 도움이되지 않았지만 여전히 같은 오류가 발생했습니다.
어떤 아이디어?
해결법
-
==============================
1.문제는 최대 절전 모드 코어에 있습니다. 종속성에서 제거하면 문제가 해결됩니다.
문제는 최대 절전 모드 코어에 있습니다. 종속성에서 제거하면 문제가 해결됩니다.
-
==============================
2.Spring Boot 2.0.3-RELEASE를 PostgreSQL 10에서 Hibernate / JPA와 함께 사용할 때도 같은 문제가있었습니다. JPA에는 다음과 같은 구성이 있습니다.
Spring Boot 2.0.3-RELEASE를 PostgreSQL 10에서 Hibernate / JPA와 함께 사용할 때도 같은 문제가있었습니다. JPA에는 다음과 같은 구성이 있습니다.
@EnableJpaRepositories public class DomainConfiguration { @Value("${database.password}") private String password; @Value("${database.url}") private String url; @Value("${database.username}") private String userName; @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(Driver.class.getCanonicalName()); dataSource.setUrl(this.url); dataSource.setUsername(this.userName); dataSource.setPassword(this.password); return dataSource; } @Bean @DependsOn("flyway") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(false); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(vendorAdapter); factory.setJpaDialect(new HibernateJpaDialect()); factory.setPersistenceUnitName("MTH"); factory.setPackagesToScan("nl.mth.sync.domain"); factory.setDataSource(dataSource()); return factory; } @Bean public Flyway flyway(DataSource dataSource) { log.debug("--- configurating flyway ---"); Flyway fly = new Flyway(); fly.setDataSource(dataSource); fly.migrate(); return fly; } @Bean public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setEntityManagerFactory(entityManagerFactory); return txManager; }
그리고 다음 방법을 추가하여 문제를 해결했습니다.
@Bean public EntityManager entityManager(LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean) { return localContainerEntityManagerFactoryBean.getObject().createEntityManager(); }
-
==============================
3.다음과 같이 표기법에 인수를 추가하여 해결할 수 있습니다.
다음과 같이 표기법에 인수를 추가하여 해결할 수 있습니다.
@SpringBootApplication
이것은 주요한 방법 일 것입니다 :
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class})
from https://stackoverflow.com/questions/42442823/sprint-boot-data-jpa-no-qualifying-bean-of-type-java-util-setjavax-persistenc by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] Spring 배치 단일 파일에서 다중 파일로 다중 스레드 처리 (0) | 2019.05.15 |
---|---|
[SPRING] 웹 아키텍처 : MVC, 지연 초기화 (Lazy initialization), 데이터 전송 객체, 열린 세션보기에서 컨센서스 접근법이 있습니까? (0) | 2019.05.15 |
[SPRING] @EnableWs가 Spring 빈에서 aop 프록시를 제거한 이유 (0) | 2019.05.15 |
[SPRING] 동적 인 Listener 수 추가 (Spring JMS) (0) | 2019.05.15 |
[SPRING] 봄 세션 + 봄 웹 소켓. 세션 ID를 기반으로 특정 클라이언트에게 메시지 보내기 (0) | 2019.05.14 |