2016-06-21 21 views
0

Spring MVCアプリケーションで作業しています。サービス層クラスがあります。ドキュメントの変換では、@Asyncアノテーションを使用します。残念ながら、非同期注釈を追加すると、プロジェクトが開始せず、現在作成中の例外のBeanが取得されます。Spring:@Asyncアノテーションを追加した後、Beanが現在作成中エラーが発生しました。

エラーログ:

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'groupAttachmentsServiceImpl': Bean with name 'groupAttachmentsServiceImpl' has been injected into other beans [groupNotesDAOImpl,personalAttachmentServiceImpl,personalNoteServiceImpl,driveQuickstartImpl,dropBoxTaskImpl,groupNotesServiceImpl,groupSectionServiceImpl,groupCanvasServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example. 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:568) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    ... 99 common frames omitted 

コード:

@Service 
@Transactional 
public class GroupAttachmentsServiceImpl implements GroupAttachmentsService { 

    private final GroupAttachmentsDAO groupAttachmentsDAO; 
@Autowired 
    public GroupAttachmentsServiceImpl(GroupAttachmentsDAO groupAttachmentsDAO) { 
     this.groupAttachmentsDAO = groupAttachmentsDAO; 
    } 

@Async 
    @Override 
    public CompletableFuture<String> createPPtxPreview(String path) { 
CompletableFuture<String> preview = new CompletableFuture<>(); 
      preview.complete("data:image/png;base64," + base64Encoder.encode(baos.toByteArray())); 
         return preview; 


     } 
} 

XML構成:

<context:component-scan base-package="com.myproj.spring"> 
     <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 
    </context:component-scan> 

    <context:property-placeholder location="classpath:application.properties"/> 

    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
       destroy-method="close"> 
     <beans:property name="driverClassName" value="org.postgresql.Driver"/> 
     <beans:property name="url" 
         value="URL"/> 
     <beans:property name="username" value="USER"/> 
     <beans:property name="password" value="PASSWORD"/> 
     <beans:property name="removeAbandoned" value="true"/> 
     <beans:property name="removeAbandonedTimeout" value="20"/> 
     <beans:property name="defaultAutoCommit" value="false"/> 
    </beans:bean> 

    <!-- Hibernate 4 SessionFactory Bean definition --> 
    <beans:bean id="hibernate4AnnotatedSessionFactory" 
       class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <beans:property name="dataSource" ref="dataSource"/> 
     <beans:property name="packagesToScan" value="com.tooltank.spring.model"/> 

     <beans:property name="hibernateProperties"> 
      <beans:props> 
       <beans:prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</beans:prop> 
       <beans:prop key="hibernate.show_sql">false</beans:prop> 
       <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop> 
       <beans:prop key="cache.use_second_level_cache">true</beans:prop> 
       <beans:prop key="cache.use_query_cache">true</beans:prop> 
      </beans:props> 
     </beans:property> 
    </beans:bean> 

    <beans:bean id="LoginServiceImpl" class="com.tooltank.spring.service.LoginServiceImpl"/> 

    <task:annotation-driven/> 

    <tx:annotation-driven transaction-manager="transactionManager"/> 

    <beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"/> 
    </beans:bean> 

    <cache:annotation-driven /> 

    <beans:bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> 
     <beans:property name="caches"> 
      <beans:set> 
       <beans:bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" 
         p:name="person"/> 
      </beans:set> 
     </beans:property> 
    </beans:bean> 

    <!-- Configuration for Spring-Data-Redis --> 
    <beans:bean id="jedisConnFactory" 
       class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:usePool="true"/> 

    <beans:bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connectionFactory-ref="jedisConnFactory"/> 


</beans:beans> 

すべてのヘルプはいいだろう。ありがとうございました。

更新

GroupAttachmentsDAO:あなたは、この特定の例外のための春の例外のドキュメントを参照してください場合

public interface GroupAttachmentsDAO { 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    boolean addAttachment(GroupAttachments attachments, int noteid); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    List<GroupAttachments> searchInGroupAttachments(int noteid, String text); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    boolean removeAllAttachmentsForNote(int noteid); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    boolean removeAttachment(int attachId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    GroupAttachments getAttachmenById(int attachId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    List<GroupAttachments> getAttachmenByNoteId(int noteId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    int returnAttachmentCount(int noteId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    void deleteAttachmentsForGroup(Long groupId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    void deleteAttachmentsForSection(int sectionid, Long groupId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    void deleteAttachmentsForCanvas(int canvasid, Long groupId); 

    @Secured({"ROLE_USER", "ROLE_ADMIN"}) 
    void deleteAttachmentsForNote(int noteid, Long groupAccountid); 

} 

答えて

1

それは

public class BeanCurrentlyInCreationException 
extends BeanCreationException 

例外原因以下の通りである: - 例外現在creに入っているBeanへの参照の場合にスローされます。 ation。通常、コンストラクタautowiringが現在構築されているBeanと一致すると発生します。

それはあなたのコードで

private final GroupAttachmentsDAO groupAttachmentsDAO; 
@Autowired 
    public GroupAttachmentsServiceImpl(GroupAttachmentsDAO groupAttachmentsDAO) { 
     this.groupAttachmentsDAO = groupAttachmentsDAO; 
    } 

コードのこの部分を(最終的に削除して、同じコードを試してみてください)使用することをお勧めを書かれているコード行に問題があることを意味します。

private GroupAttachmentsDAO groupAttachmentsDAO; //remove final 
    @Autowired 
     public GroupAttachmentsServiceImpl(GroupAttachmentsDAO groupAttachmentsDAO) { 
      this.groupAttachmentsDAO = groupAttachmentsDAO; 
     } 

フィールド上@Autowiredfinalを持つため、矛盾しています。

+0

あなたが提案した変更で、私はエラーが発生し、groupAttachmentsDAOは初期化されていない可能性があります。私がファイナルを取り除くと、以前と同じエラーが出ています。何かご意見は? –

+0

また、GroupAttachmentsDAOはインターフェイスです.... –

+0

はあなたのクラス 'GroupAttachmentsDAO'が'リソース 'または'サービス 'または' bean'として設定されていますか?私はコメントで言及しました.. クラス 'GroupAttachmentsDAO'の定義を投稿してください。問題を特定するのに役立つかもしれません。 ありがとう.. –

関連する問題