Java批处理-将ejb注入批处理

问题描述 投票:1回答:1

我有一个启动bean。我想在此开始一些小批量工作。我使用@Nemed@Dependent注释了批处理类。我想在批处理中使用诸如ReportService之类的ejb,但注入功能不起作用。如何将EJB注入我的批处理中?我将以下示例部署在wildfly 11.0.0.Alpha1上,并在服务对象中获得空引用。

BatchletTest:

@Dependent
@Named("BatchletTest")
public class BatchletTest extends AbstractBatchlet{


    public BatchletTest() {
    }

    @Inject
    ReportService service;

    @Override
    public String process() throws Exception {
        System.out.println(service);
        return null;
    }
}

test-job.xml

 <job id="test-job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
        <step id="testStep">
            <batchlet ref="com.test.BatchletTest" />
        </step>
    </job>

StartupBean:

@Singleton
@Startup
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class StartupBean {

    private Logger logger = LoggerFactory.getLogger(StartupBean.class);

    @PostConstruct
    private void startup() throws Exception {
            long executionId = BatchRuntime.getJobOperator().start("test-job", new Properties());
            System.out.println("myJob started, execution ID = " + executionId);

    }

}

ReportService:

@Stateless
public class ReportService {
.....
}
ejb cdi java-batch jberet jbatch
1个回答
0
投票

您没有在类ReportService上使用@Local anntotaion实现任何接口。

尝试一下:

@Stateless
@LocalBean
public class ReportService {
.....
}

@Stateless
public class ReportService implements ReportServiceLocal{
.....
}

@Local
public interface ReportServiceLocal {
.....
}

请检查此link

© www.soinside.com 2019 - 2024. All rights reserved.