요청된 bean이 현재 생성 중입니다.해결할 수 없는 순환 참조가 있습니까?
spring 3을 사용하고 있으며, 2개의 뷰 스코프가 있습니다.
1 - Bean 1 :
@Component("bean1")
@Scope("view")
public class Bean1 {
@Autowired
private Bean2 bean2;
}
2 - Bean2 :
@Component("bean2")
@Scope("view")
public class Bean2 {
@Autowired
private Bean1 bean1;
}
뷰는 커스텀 스코프입니다.
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="view">
<bean class="${project.groupId}.utils.ViewScope" />
</entry>
</map>
</property>
</bean>
커스텀 뷰 범위의 코드는 다음과 같습니다.
public class ViewScope implements Scope {
@SuppressWarnings("rawtypes")
public Object get(String name, ObjectFactory objectFactory) {
Map<String, Object> viewMap = FacesContext.getCurrentInstance()
.getViewRoot().getViewMap();
if (viewMap.containsKey(name)) {
return viewMap.get(name);
} else {
Object object = objectFactory.getObject();
viewMap.put(name, object);
return object;
}
}
public Object remove(String name) {
return FacesContext.getCurrentInstance().getViewRoot().getViewMap()
.remove(name);
}
public String getConversationId() {
return null;
}
public void registerDestructionCallback(String name, Runnable callback) {
// Not supported
}
public Object resolveContextualObject(String key) {
return null;
}
}
두 개의 콩을 모두 사용하는 페이지를 열었을 때, 나는 예외를 받는다:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'agencyBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
at com.myapp.utils.ViewScope.get(ViewScope.java:20)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:329)
at com.xeno.xecamp.webManagement.utils.ViewScope.get(ViewScope.java:20)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:56)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
at org.apache.el.parser.AstValue.invoke(AstValue.java:244)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2508)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2139)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2087)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:286)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:244)
at org.springframework.faces.webflow.Jsf2FlowApplication.publishEvent(Jsf2FlowApplication.java:94)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:99)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:60)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:57)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
이 예외를 수정하는 방법을 조언해 주십시오.
EDIT: 여기 답변에서 참조된 대로 세터 주입을 사용하려고 했습니다.
근데 그것도 안 돼요
1 - Bean 1 :
@Component("bean1")
@Scope("view")
public class Bean1 {
private Bean2 bean2;
@Autowired
public void setBean2 (Bean2 bean2) {
this.bean2= bean2;
}
}
2 - Bean2 :
@Component("bean2")
@Scope("view")
public class Bean2 {
private Bean1 bean1;
@Autowired
public void setBean1 (Bean1 bean1) {
this.bean1= bean1;
}
}
하지만 예외는 있습니다.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.myapp.beans.Bean1] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
Spring's가 좋을 것 같아요.
@ 게으름뱅이
자동 배선 필드 중 하나에 주석을 달아 순환 종속성을 해제합니다.
이것이 Spring 버전에서도 동작/종료할 수 있을지는 잘 모르겠습니다.
스프링은 싱글톤 콩으로 이런 종류의 순환 의존성을 해결하기 위해 특별한 논리를 사용합니다.그러나 이것은 다른 범위에는 적용되지 않습니다.이러한 순환 의존성을 타파하는 우아한 방법은 없지만, 서투른 선택은 다음과 같습니다.
@Component("bean1")
@Scope("view")
public class Bean1 {
@Autowired
private Bean2 bean2;
@PostConstruct
public void init() {
bean2.setBean1(this);
}
}
@Component("bean2")
@Scope("view")
public class Bean2 {
private Bean1 bean1;
public void setBean1(Bean1 bean1) {
this.bean1 = bean1;
}
}
어쨌든 순환 의존성은 대개 설계가 잘못되어 나타나는 증상입니다.클래스 의존성을 정의할 수 있는 더 나은 방법이 있다면 다시 생각해 볼 수 있습니다.
제 경우 bean을 정의하고 같은 클래스 파일의 컨스트럭터에 자동 접속하고 있었습니다.
@SpringBootApplication
public class MyApplication {
private MyBean myBean;
public MyApplication(MyBean myBean) {
this.myBean = myBean;
}
@Bean
public MyBean myBean() {
return new MyBean();
}
}
해결책은 bean 정의를 다른 클래스 파일로 이동하는 것이었습니다.
@Configuration
public CustomConfig {
@Bean
public MyBean myBean() {
return new MyBean();
}
}
중요: 마지막에 있는 편집 내용을 읽습니다.
또한 Spring을 2.6.6으로 업그레이드한 후에도 이 예외가 발생했습니다(이는 관련이 없을 수도 있고 관련이 없을 수도 있습니다).
ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'webSecurityConfig':
Requested bean is currently in creation: Is there an unresolvable circular reference?
제 클래스는 Web Security Configurer Adapter를 확장하고 있었습니다.이것은 @Configuration & @EnableWebSecurity 주석을 사용하는 설정 클래스입니다.
어쨌든, 저에게 효과가 있었던 솔루션은, https://errorsfixing.com/error-creating-bean-with-name-securityconfig-requested-bean-is-currently-in-creation/ 입니다.
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
..."some code"...
}
변경 후 이 방법은 다음과 같습니다.
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
..."same code"...
}
그래서 방금 @Autowired를 @Override로 변경하고 메서드의 이름을 configure()로 변경했습니다.
편집:
이 변화는 나에게 예상치 못한 문제를 가져왔다.설정에서는 여러 Authentication Provider를 사용할 수 있습니다.또한 SecurityConfig 클래스에서 정의된 WebSecurityConfigrAdapter를 확장하는 여러 서브클래스가 있습니다.
문제: 대부분의 경우(실제로 모든 경우) 잘못된 Authentication Provider가 호출되었습니다.
그 결과:@Autowired로 돌아가서 configureGlobal :/ application.yml 스프링 구성에 다음 플래그를 추가하면 순환 종속성을 "무시"할 수 있습니다.
spring:
main:
allow-circular-references: true
저의 솔루션은 bean 정의를 다른 클래스의 구성으로 이동하는 것이었습니다.
@Configuration
public class EncoderConfig {
@Bean
PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
}
나는 꽤 어리석은 방법으로 이 오류를 만났다.
@Autowired
// private Bean bean;
public void myMethod() {
return;
}
무슨 일이 있었냐면 내가 어떤 이유로 한 줄을 코멘트하고 주석을 남겼기 때문에 스프링은 그 방법이 자동 파워가 필요하다고 생각했다.
일반적으로 순환 의존성에 대처하는 방법은 세터 주입을 사용하는 것입니다.
당신이 올린 세터 주사 코드를 시도해 봤는데 효과가 있었어요.당신이 예외를 두는 이유는 Bean1과 Bean2가 com.myapp에 있기 때문이라고 생각합니다.beats 패키지로 해당 패키지에 대해 컴포넌트 스캔이 활성화되지 않았습니다.
스프링 구성에 다음 항목을 추가해야 합니다.
<context:component-scan base-package="com.bullethq.accounts.web"/>
또는 스프링에 의해 자동으로 스캔되는 패키지로 콩을 옮깁니다.
그렇게 사용하세요, 둘 다@Autowired
그리고.@Lazy
주석:
@Autowired
@Lazy
ServiceClass serviceClass;
@FaZoM 크레딧.
어플리케이션 파일에 다음 항목을 추가하여 해결했습니다.
spring.main.allow-circular-references=true
@필드 레벨의 리소스 주석을 사용하여 런타임에 룩업을 선언할 수도 있습니다.
1. 테스트용 비테스트 보안 구성을 비활성화합니다.
@EnableWebSecurity
@Profile("!test")
public class SecurityConfig extends WebSecurityConfigurerAdapter { ... }
2. 테스트 폴더에 테스트 보안 구성 추가
@TestConfiguration
public class TestSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("**/*").anonymous();
}
}
3. 통합 테스트에 Test Config 추가
@SpringBootTest(webEnvironment = RANDOM_PORT)
@ContextConfiguration(classes = TestSecurityConfig.class)
public class IntegrationTest { ... }
클래스에서 Web Security Configurer Adapter를 확장한 메서드를 1개 변경했는데 다음과 같습니다.
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
}
여기에
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
}
나한테는 효과가 있었어요
일반적으로 이 문제를 회피하는 가장 적절한 방법은 (또한 JUnit에서의 Mockito 통합이 향상되었기 때문에) https://www.baeldung.com/circular-dependencies-in-spring 및 https://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html에서 설명한 바와 같이 Setter/Field Injection을 사용하는 것입니다.
@Component("bean1")
@Scope("view")
public class Bean1 {
private Bean2 bean2;
@Autowired
public void setBean2(Bean2 bean2) {
this.bean2 = bean2;
}
}
@Component("bean2")
@Scope("view")
public class Bean2 {
private Bean1 bean1;
@Autowired
public void setBean1(Bean1 bean1) {
this.bean1 = bean1;
}
}
아래 오류가 발생하고 있습니다.
원인: org.springframework.콩류.Bean Current In Creation(빈 현재 생성)예외:이름이 'objectMapper'인 콩을 만드는 동안 오류가 발생했습니다. 요청된 콩은 현재 생성 중입니다. 해결할 수 없는 순환 참조가 있습니까?org.springframework에 있습니다.콩류.지지하다.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355)~[ spring-beans-5.2.11 ]org.springframework에서 RELEASE.jar:5.2.11.RELEASE]를 참조해 주세요.콩류.지지하다.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227)~[ spring - beans - 5 . 2 . 11 ]org.springframework에서 RELEASE.jar:5.2.11.RELEASE]를 참조해 주세요.콩류.지지하다.Abstract Bean Factory.DoGet Bean(Abstract Bean Factory.java:322)~[ spring - bean - 5 . 2 . 11 ]RELEASE.jar: 5.2.11.RELEASE]
@Lazy를 추가하여 해결했습니다.
**@Lazy**
@Autowired()
private ObjectMapper objectMapper;
언급URL : https://stackoverflow.com/questions/10008714/requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-refer
'programing' 카테고리의 다른 글
Wordpress 플러그인 설치 - FTP 서버에 연결하지 못했습니다 - 가장 안전한 솔루션? (0) | 2023.03.08 |
---|---|
처리에서 보류로 주문이 작성될 때 WooCommerce 주문 상태 설정 (0) | 2023.03.08 |
MongoDB 색인된 컬럼의 count(구분 x) 선택 - 대용량 데이터 세트에 대한 고유 결과 카운트 (0) | 2023.03.08 |
2시간 이상 경과한 Firebase 데이터 삭제 (0) | 2023.03.08 |
스프링: 경로에 대한 /**와 /*의 차이 (0) | 2023.02.26 |