私は、Spring DataとSpringに基づくJavaプロジェクトを持っています。Java Springデータ@Autowired issue
私はSpring BeanとSpringデータリポジトリをautowiredしています。そして、私はこの豆をフィールドとして自分自身に注入したい。
マイBeanは次のとおりです。
@Service @Transactional public class JobService {
@Autowired private ChatMessagesRepository chatMessagesRepository;
}
しかし、私は自分自身にこのBeanを注入しようとした場合、すべての春のデータは(と私は他人豆を信じて)クラッシュをオートワイヤリング、null
になります。なぜそれが起こるかもしれませんか?
マイ設定:
....
<aop:aspectj-autoproxy proxy-target-class="true"/>
<mvc:annotation-driven/>
<jpa:repositories base-package="..."
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<context:annotation-config/>
<context:component-scan base-package="...">
<context:exclude-filter type="annotation"
expression="org.springframework.context.annotation.Configuration"/>
</context:component-scan>
....
これはsingerball beanです。 – avalon
他のスコープを試しましたか? –
私はJobService内の1つのメソッドをREQUIRES_NEWトランザクション内のこのクラスの他のメソッドから呼び出すようにしますが、別のメソッドから1つだけ呼び出すと、トランザクションは同じになります。 – avalon