2013-10-18 47 views
1

我有一個Java EE項目打包在耳邊。耳朵包含一個Jar,我打包了我的@stateless EJB和其他未管理的類(我的模型,utils等)。對於其中一些EJB,我使用Jax-W將它們的功能作爲Web服務公開。使用wsgen和@Interceptors原因 - >不支持major.minor版本51.0

我嘗試使用AOP創建日誌記錄機制,因此我將@Interceptors註釋放入Jax-Ws驅動的EJB中。問題是,當我嘗試使用maven編譯/構建/包時,我收到以下異常。這似乎是問題是特定於wsgen的原因,當我把@Interceptors註釋在NON Jax-ws註釋的EJBs編譯和運行沒有任何問題。我使用JAva build 1.6.0_41-b02。

我也試着找到javax.interceptor-api的老版本(可能在Java 1.6中編譯,因爲major.minor版本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 

我POM(部分):

<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 
{....} 

回答

0

您嘗試web-beans.xml代替annotation?如果沒有請檢查this is link。可能是Maven插件不認識這個註釋。

類級別的聲明應該是這樣的代碼:

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

而且這個攔截器需要啓用:

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

我沒有測試這些代碼。

0

您發送的web-beans.xml聲明是特定於jboss的?我使用Web邏輯並發現可以通過在META-INF/beans.xml中添加以下xml來啓用攔截器。

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

我會盡量XML聲明,而是因爲我很着急,我利用由JAX-WS框架本身提供的處理程序的功能(使用@HandlerChain批註)爲「攔截」的Web服務請求和響應。

0

我也嘗試使用@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> 
相關問題