次のテストクラスがあります。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:ApplicationContext.xml")
public class CompoundServiceImplTest {
@Autowired
@Qualifier("testCompoundService")
private TestCompoundService testCompoundService;
//...
}
およびApplicationContextに含まれるもの:
<bean id="testCompoundService" autowire="byType"
class="myPackage.TestCompoundService">
</bean>
また、byNameの自動配線を試したり、@ Qualifierを残したりした場合(機能しなかったため追加しましたが、どちらも役に立ちませんでした)。
次の例外が発生します:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [myPackage.TestCompoundService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true),
@org.springframework.beans.factory.annotation.Qualifier(value=testCompoundService)}
Beanは明確に構成されていますが、春はそうではないと主張していますか?
どうすればこれを解決できますか?
編集:
@Autowiredを@Resourceに変更すると、次のエラーが発生します。
Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'testCompoundService' must be of type [myPackage.TestCompoundService],
but was actually of type [$Proxy68]