Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将EJB注入启动单例bean_Java_Jakarta Ee_Java Ee 6 - Fatal编程技术网

Java 将EJB注入启动单例bean

Java 将EJB注入启动单例bean,java,jakarta-ee,java-ee-6,Java,Jakarta Ee,Java Ee 6,在我的应用程序中,我有以下启动bean: @Startup @Singleton @DependsOn("RecordAcumulator") public class StartupBean { private static final Logger logger = Logger.getLogger(StartupBean.class); @Inject RecordAcumulator recordAcumulator; /** * Initi

在我的应用程序中,我有以下启动bean:

@Startup
@Singleton
@DependsOn("RecordAcumulator")
public class StartupBean {
    private static final Logger logger = Logger.getLogger(StartupBean.class);

    @Inject
    RecordAcumulator recordAcumulator;

    /**
     * Initializes the EJB system on the post construct event
     */
    @PostConstruct
    public void init() {
记录累加器是访问数据库的EJB。启动旨在将数据库表预加载到缓存中

@Stateless
public class RecordAcumulator {
当它启动时,我会

Caused by: com.ibm.ws.exception.RuntimeWarning: CNTR0200E: The StartupBean singleton session bean in the EJB.jar module depends on the RecordAcumulator enterprise bean in the EJB.jar, but the target is not a singleton session bean.
我已经尝试了很多不同的方法,但我似乎无法注射。我的日志文件表明RecordAcumulator EJB是在加载启动bean之前绑定的,所以我不明白为什么我不能将EJB注入启动中

如果我删除@DependsOn,我会得到以下结果:

Caused by: javax.ejb.NoSuchEJBException: An error occurred during initialization of singleton session bean bla#EJB.jar#StartupBean, resulting in the discarding of the singleton instance.; nested exception is: javax.ejb.EJBException: The @Inject java.lang.reflect.Field.recordAcumulator reference of type com.foo.bar.accum.RecordAcumulator for the StartupBean component in the EJB.jar module of the bla application cannot be resolved.
有没有办法解决这个问题

编辑---------- 我找到了这个链接:

但问题是我使用的是8.5.5.0,这个问题应该在8.5.0.2中解决,从我所看到的:

  • 删除
    @DependsOn
  • 使您的EJB
    @Singleton

  • 可能会有,因为通过应用程序的所有流量都将通过该实例。在您的情况下,这可能不是问题。

    问题在于RecordAcumulator EJB是系统中使用最频繁的类。它甚至在同一个函数中与WAS work manager线程并行调用多次。我不想让它成为一个单例,因为我需要EJBAh的事务隔离特性好吧,我上面提到的就是这种危险。没有从你的问题中得到这样的印象:)对不起。