我正在尝试让Spring data JPA与EJB和CDI (Java EE 7)协同工作。好吧,我遵循了文档(http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/jpa.repositories.html#jpd.misc.cdi-integration),但是仍然不能@在无状态的ejb中注入我的存储库。代码如下:
@Configuration
@EnableJpaRepositories
public class EntityManagerFactoryProducer {
@Produces
@ApplicationScoped
public EntityManagerFactory entityManagerFactory() {
return Persistence.createEntityManagerFactory("mypu");
}
public void close(@Disposes EntityManagerFactory entityManagerFactory) {
entityManagerFactory.close();
}
}$
public interface TipoFolhaRepository extends JpaRepository<TipoFolha, Long> {
List<TipoFolha> findByNome(String nome);
TipoFolha findByTipo(String tipo);
}$
@Stateless
public class TipoFolhaFacade extends AbstractFacade<TipoFolha> {
@Inject
TipoFolhaRepository tpRepo;
@Override
public List<TipoFolha> findAll(){
return tpRepo.findAll();
}
}跟随错误。WELD-001408在注入点具有限定符@ TipoFolhaRepository的类型默认不满足的依赖项[BackedAnnotatedField @Inject com.mycompany.ejb.TipoFolhaFacade.tpRepo]
我遗漏了什么?
发布于 2017-01-03 19:22:08
您需要在存储库类所在的模块中使用bean-discovery-mode="all"启用CDI。这意味着在META-INF文件夹中创建一个包含以下内容的beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>在this Oracle blogpost中可以找到对不同发现模式的简短说明
https://stackoverflow.com/questions/19713128
复制相似问题