6
我正在嘗試做簡單的事情。在CDI中注入合格的String
(或File
)。在CDI中注入帶有限定符的字符串
所以我有一個限定詞:
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD,METHOD,PARAMETER,TYPE})
@Qualifier
public @interface FilesRepositoryPath {}
我有一個製片人:
public class FilesRepositoryPathProducer {
@Produces
@FilesRepositoryPath
public String getRepositoryDirectory() {
return "path.taken.from.configuration";
}
}
而且我嘗試使用它:
@ApplicationScoped
public class FilesRepository {
@Inject
public FilesRepository(@FilesRepositoryPath String filesDirectory) {
//Do some stuff
}
}
然而,焊縫不能實例這個bean。我得到一個異常:
org.jboss.arquillian.impl.event.FiredEventException: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001410 The injection point [field] @Inject private za.co.fnb.commercial.dms.file.FilesRepositoryBeanTest.repo has non-proxyable dependencies
我知道String
是unproxable,但爲什麼WELD希望創建一個代理?它有@Dependent
範圍,所以AFAIK它不應該創建代理無論如何。我怎樣才能使它工作?
您可以發佈'FilesRepositoryBeanTest'好嗎? – 2011-04-21 05:01:53
在焊接中存在問題。根據規範,代碼似乎沒問題。 – Bozho 2011-04-23 21:18:26
看看這裏:http://stackoverflow.com/questions/7583871/injecting-a-named-string-using-cdi,似乎是一個類似的問題 – Kris 2011-12-01 14:17:19