使用 wsgen 和 @Interceptors 原因 --> 不支持的 major.minor 版本 51.0



我有一个Java EE项目打包在耳朵上。耳朵包含一个 Jar,我在其中打包了我的 @stateless EJB 和其他非托管类(我的模型、实用程序等)。对于其中一些 EJB,我使用 Jax-W 将它们的功能公开为 Web 服务。

我尝试使用 AOP 创建一个日志记录机制,因此我将@Interceptors注释放在我的 Jax-Ws 驱动的 EJB 中。问题是当我尝试使用 maven 编译/构建/打包时,我收到以下异常。当我将@Interceptors注释放在它编译和运行的 NON Jax-ws 注释的 EJB 中时,似乎问题特定于 wsgen 原因。我使用 JAva build 1.6.0_41-b02。

我还试图找到一个旧版本的javax.interceptor-api(可能是用Java 1.6编译的,因为major.minor version 51.0意味着它已经在JSE 7中编译,如果我做对的话),但似乎1.2是旧的。

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsgen (MyWebService) on pro
ect my-ws-ejb: Failed to execute wsgen: javax/interceptor/Interceptors : Unsupported major.minor version 51.0 -> [Help
1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plu
in:2.2:wsgen (MyWebService) on project my-ws-ejb: Failed to execute wsgen
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to execute wsgen
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:148)
        at org.jvnet.jax_ws_commons.jaxws.MainWsGenMojo.execute(MainWsGenMojo.java:95)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: java.lang.UnsupportedClassVersionError: javax/interceptor/Interceptors : Unsupported major.minor version 51.
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:249)
        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:181)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
        at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079)
        at java.lang.Class.getAnnotation(Class.java:3038)
        at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:240)
        at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:222)
        at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123)
        at com.sun.tools.ws.WsGen.doMain(WsGen.java:74)
        at org.jvnet.jax_ws_commons.jaxws.AbstractWsGenMojo.execute(AbstractWsGenMojo.java:142)
        ... 22 more

我的绒球(部分):

    <build>
            <!-- The name of the jar file -->
            <finalName>my-ws-ejb</finalName>
            <plugins>
                <!-- Use EJB 3.0 -->
                <plugin>
                    <groupId>org.apache.maven.plugins
                    </groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <ejbVersion>3.0</ejbVersion>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jax-ws-commons</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <version>2.2</version>
                    <executions>
                        <!-- The WSDLs to be generated are placed here -->
                        <execution>
                            <id>MyWebService</id>
                            <configuration>
                                <sei>MyWebServiceBean</sei>
                                <genWsdl>true</genWsdl>
                                <keep>true</keep>
                                <verbose>true</verbose>
                            </configuration>
                            <goals>
                                <goal>wsgen</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <!-- Build with Java 6 -->
                            <source>1.6</source>
                            <target>1.6</target>
                            <!-- Show deprecations and warnings -->
                            <showDeprecation>true</showDeprecation>
                            <showWarnings>true</showWarnings>
                        </configuration>
                    </plugin>
            </plugins>
        </build>
        <dependencies>
            <!-- EJB 3 -->
            <dependency>
                <groupId>javax.ejb</groupId>
                <artifactId>ejb</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <!-- EclipseLink -->
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.persistence</groupId>
                <artifactId>persistence</artifactId>
                <version>1.0.0.0_2-0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Oracle JDBC driver -->
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc6</artifactId>
                <version>11.1.0.7.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- AOP -->
            <dependency>
                <groupId>javax.interceptor</groupId>
                <artifactId>javax.interceptor-api</artifactId>
                <version>1.2</version>
            </dependency>
.....
</dependencies>

我的豆子(部分)

@Interceptors(LoggingAopService.class)
@WebService(
        serviceName = "MyWebService", portName = "MyWebService",
        targetNamespace = "..."
)
@Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
public class MyWebServiceBean implements MyWebService
{....}

你是在尝试web-beans.xml而不是annotation吗? 如果没有,请检查这是链接。可能是 maven 插件无法识别此注释。

类级别声明应类似于以下代码:

<myapp:MyWebServiceBean>
   <myfwk:LoggingAopService/>
</myapp:MyWebServiceBean>

并且此拦截器需要启用:

<Interceptors>
    <myfwk:LoggingAopService/>
</Interceptors>

我没有测试这些代码。

web-beans.xml您发送的声明是特定于 jboss 的吗? 我使用 Web 逻辑,发现拦截器可以通过在 META-INF/beans.xml 中添加的以下 xml 来启用。

<interceptors>
    <class>org.samples.LoggingInterceptor</class>
</interceptors>

我将尝试 xml 声明,但因为我赶时间,我利用 Jax-Ws 框架原生提供的处理程序功能(使用@HandlerChain注释)来"拦截"Web 服务请求和响应。

我还尝试使用以下@InterceptorBinding方式创建一个新的注释:

@Inherited
    @InterceptorBinding
    @Retention(RUNTIME)
    @Target({ METHOD, TYPE })
    public @interface Logging {
    }

@Interceptor
    @Logging
    public class LoggingInterceptor {
        @AroundInvoke
        public Object intercept(InvocationContext context) throws Exception {...}

 @Logging
    @WebService(serviceName = "MyWebService", portName = "MyWebService",
    targetNamespace = "...")
    @Stateless(name = "MyWebServiceBean", mappedName = "ejb/seb/MyWebServiceBean")
    public class MyWebServiceBean implements MyWebService
    {....}

但这也不能编译,我收到同样的错误:

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:w
sgen (EDocWebService) on project eDoc-ws-ejb: Failed to execute wsgen: javax/int
erceptor/InterceptorBinding : Unsupported major.minor version 51.0 -> [Help 1]

可能这是应该使用 ejb-jar.xml

的情况
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
      <interceptors>
        <interceptor>
          <interceptor-class>com.mypackage.LoggingInterceptor </interceptor-class>
        </interceptor>
      </interceptors>
      <assembly-descriptor>
        <interceptor-binding>
          <ejb-name>MyWebServiceBean</ejb-name>
          <interceptor-class>com.package.Interceptor</interceptor-class>
        </interceptor-binding>
      </assembly-descriptor>
 </ejb-jar>

相关内容

  • 没有找到相关文章