在EJB JAR中焊接“Enclosing method not found”异常

时间:2015-07-30 22:45:07

标签: ejb cdi wildfly

在启用CDI的情况下将EJB Jar部署到WildFly 8.2.0(即使用最小的beans.xml文件)导致抛出“Enclosing method not found”异常。在日志中没有什么特别有用的方法来识别错误的来源。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

这是因为我的EJB Jar由Gradle创建为“Fat”jar,即

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from {
        configurations.compile
            .collect {
                println it
                it.isDirectory() ? it : zipTree(it)
            }
    }
    with jar
}

我还引用了这些工件,以便访问我需要的Java EE库:

compile 'javax:javaee-api:7.0'
compile 'javax:javaee-web-api:7.0'
compile 'javax.jms:jms:1.1'

问题是这些Javax库被拉入JAR,这是不必要的,因为Wildfly已经提供了它们。重复导致了Weld异常。

解决方案是从Fat JAR中排除这些Javax库:

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from {
        configurations.compile
            /*
                Effectively the javax libraries are provided in scope,
                so don't add them to the jar. Failing to exclude these
                leads to Weld CDI exceptions like
             */
            .findAll {
                it.toString().indexOf('javax') == -1
            }
            .collect {
                println it
                it.isDirectory() ? it : zipTree(it)
            }
    }
    with jar
}

通过此更改,异常消失了。

相关问题