CDI:来自jar的接口无法解析为Local Wildfly 8.0

时间:2015-07-30 10:24:01

标签: java cdi wildfly

我正在尝试将现有的Java 7应用程序从Jboss 7.1迁移到Wildfly 8.0并面临CDI的一些问题。

项目的结构如下:

 ear
    |
    |--> base.service.impl.war
    |--> mad.impl.war --> contains SessionServiceImpl.class
    |--> lib
        |
        |-> base.api.jar
        |-> base.api.impl.jar --> contains SessionService.class

SessionService是纯Java接口,没有注释。 SessionServiceImpl如下所示:

@Stateless
@EJB(name = SessionService.JNDI_NAME, beanInterface = SessionService.class)
public class SessionServiceImpl implements SessionService {

}

EJB似乎已注册:

INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named SessionServiceImpl in deployment unit subdeployment "com.mad.impl.war" of deployment "com.deployment.ear.ear" are as follows:

    java:global/com.server.deployment.ear/com.mad.impl/SessionServiceImpl!com.base.session.SessionService
    java:app/com.mad.impl/SessionServiceImpl!com.base.session.SessionService
    java:module/SessionServiceImpl!com.base.session.SessionService
    java:global/com.deployment.ear/com.mad.impl/SessionServiceImpl
    java:app/com.mad.impl/SessionServiceImpl
    java:module/SessionServiceImpl

但在此之后,当CDI容器开始部署时,我遇到以下错误:

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."com.deployment.ear.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."com.deployment.ear.ear".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Caused by: org.jboss.msc.service.ServiceNotFoundException: Service service jboss.deployment.subunit."com.deployment.ear.ear"."com.mad.impl.war".component.SessionServiceImpl.VIEW."com.base.session.SessionService".LOCAL not found

我试图用@Local注释界面,但这没有帮助。

Maven ear-plugin配置如下:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <version>6</version>
                <initializeInOrder>true</initializeInOrder>
                <defaultLibBundleDir>/lib</defaultLibBundleDir>
                <modules>
                    <jarModule>
                            <groupId>mygroup</groupId>
                            <artifactId>com.base.impl</artifactId>
                        </jarModule>

                        <webModule>
                            <groupId>mygroup</groupId>
                            <artifactId>com.base.service.impl</artifactId>
                            <contextRoot>/impl.base.server</contextRoot>
                            <bundleFileName>com.base.impl.war</bundleFileName>
                        </webModule>

                        <webModule>
                            <groupId>mygroup</groupId>
                            <artifactId>com.mad.impl</artifactId>
                            <contextRoot>/impl.mad.server</contextRoot>
                            <bundleFileName>com.mad.impl.war</bundleFileName>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>

2 个答案:

答案 0 :(得分:0)

问题在于无状态bean。 CDI在为会话bean注入远程接口时遇到问题。正如错误所示,它正在尝试为SessionServiceImpl注入LOCAL接口,但这不可能发生,因为ejb容器(基于ejb规范)仅暴露了远程接口,因为您的SessionServiceImpl实现了SessionService,并且未使用@注释LocalBean。

关于ejb3.1的注意事项:

  • 如果会话bean实现Serializable以外的任何接口, 可比较,可外部化,然后实现的接口将是 被认为是bean的远程接口。
  • 此外,您已使用@EJB注释定义了遥控器 您的SessionServiceImpl的接口,因此它没有被放入 LOCAL命名空间,但在REMOTE名称空间中。

答案 1 :(得分:0)

最后从application.xml中删除<initialize-in-order>true</initialize-in-order>似乎是一招。 (https://developer.jboss.org/thread/243482)。另外,我必须使用@Inject替换一些@EJB注释。