第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring bean 的創(chuàng)建問題?

Spring bean 的創(chuàng)建問題?

溫溫醬 2019-01-18 03:37:46
先上我的代碼 @Component @Slf4j public class CSPDJournalListTask { @Autowired ArticleEntityRepository articleEntityRepository; @Async public void task2(){ List<ArticleEntity> list = articleEntityRepository.findAll(); System.out.println(list.toString()); } } 上面是一個異步任務,使用SpringBoot創(chuàng)建,并且已經(jīng)添加了 @EnableAsync注解 接下來,我就創(chuàng)建了一個簡單地單元測試,如下: @RunWith(SpringRunner.class) @SpringBootTest public class CSPDJournalListProcessorTest { @Autowired CSPDJournalListTask cspdJournalListTask; @Test public void test() { cspdJournalListTask.task(); } } 然后,詭異的事情發(fā)生了,拋出了如下異常 org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:208) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:515) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:290) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:168) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:150) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135) ~[spring-data-jpa-2.0.8.RELEASE.jar:2.0.8.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.8.RELEASE.jar:2.0.8.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at com.sun.proxy.$Proxy89.findAll(Unknown Source) ~[na:na] at com.example.webmagic_demo.article.CSPDJournalListTask.task2(CSPDJournalListTask.java:43) ~[classes/:na] at com.example.webmagic_demo.article.CSPDJournalListTask$$FastClassBySpringCGLIB$$c9b82008.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_171] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171] 重點看這句: Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!) 好像是說我使用的單實例bean已經(jīng)關閉了,難道時因為這個異步的原因嗎? 如果需要在異步任務中這樣做,該怎么實現(xiàn)呢? 希望大神們看到解答一下,非常感謝!
查看完整描述

2 回答

?
蝴蝶刀刀

TA貢獻1801條經(jīng)驗 獲得超8個贊

這里貼出我的代碼,一點問題也沒有


@EnableAsync
@SpringBootApplication
public class Example {

}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Example.class)
public class Test1 {
    @Autowired
    CSPDJournalListTask cspdJournalListTask;

    @Test
    public void test() {
        cspdJournalListTask.task();
    }
}
@Component
public class CSPDJournalListTask {

        
        @Async
        public void task() {
            // TODO Auto-generated method stub
             System.out.println("async");
        }
        
}

首先要明確的一點是這個錯誤肯定不是因為使用了async, BeanCreationNotAllowedException大概率是因為項目配置問題,比如jar之間相互沖突不兼容之類的,建議從最簡單的項目配置開始,能跑起來之后再增加配置。

查看完整回答
反對 回復 2019-02-12
  • 2 回答
  • 0 關注
  • 598 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號